I need help with sql code

i have the next stucture:

table 1: students: id, name, age
table 2: subjects: id, name(like history)
table 3: id, student_id, subject_id, mark

I want the one table will show me all the marks with inner join function and i don’t success to do so.
Please help me with this coding. thanks you.

This will help yyou get started

[php]SELECT *
FROM
test.table1
INNER JOIN test.table3
ON (table1.id = table3.student_id)
INNER JOIN test.table2
ON (table3.subject_id = table2.id)
WHERE table3.student_id= 1;[/php]

result of student _id = 1

[code]id name age id student_id subject_id mark id name
1 james 12 1 1 1 6 1 history
1 james 12 3 1 4 8 4 german

[/code]

or if you wanted it by make greater than

[php]SELECT *
FROM
test.table1
INNER JOIN test.table3
ON (table1.id = table3.student_id)
INNER JOIN test.table2
ON (table3.subject_id = table2.id)
WHERE table3.mark>= 1;[/php]
result greater than or equal to 1

id	name	age	id	student_id	subject_id	mark	id	name
1	james	12	1	1		1		6	1	history
2	mark	15	2	2		1		7	1	history
1	james	12	3	1		4		8	4	german
3	david	17	4	3		1		9	1	history
3	david	17	5	3		2		10	2	english

Thank you!
i will try this right now and i hope to success

This will give you the Name the Subject and the Mark
[php]
SELECT name,subject_id,mark) FROM test.table1 INNER JOIN test.table3 ON (table1.id = table3.student_id) INNER JOIN test.table2 ON (table3.subject_id = table2.id) WHERE table3.student_id= 1;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service