I have three tables:
student: sub: marks:
id | name id | sub stud_id | sub_id | marks
---+-------- ---+------------ --------+----------+------
1 | Peter 1 | English 1 | 1 | 80
2 | Alice 2 | Maths 1 | 2 | 70
3 | History 2 | 1 | 90
2 | 2 | 80
I need to make a query that returns this:
name | subjects | marks
-------+-----------+----------------------------
Peter | English | 80
Peter | Maths | 70
Peter | History | 0
This is what I tried:
select *
from student s
LEFT JOIN stud_marks m ON s.id = m.stud_id
RIGHT JOIN subjects sub ON sub.id = m.sub_id
which got me
name | marks | sub ------+--------+---------- Peter | 80 | English Peter | 70 | Maths Alice | 90 | English Alice | 80 | Maths | | History
Any ideas?