我有这些记录:
Table siswa
student_id | student_name |
---------------------------
1 | Abi |
2 | Bayu |
3 | Charles |
Table nilai
semester | subject | student_id | mark |
----------------------------------------
1 | 1 | 1 | 7 |
1 | 1 | 2 | 9 |
1 | 1 | 3 | 8 |
1 | 2 | 1 | 4 |
1 | 2 | 2 | 6 |
2 | 1 | 1 | 9 |
我将在第 2 学期和第 1 科目中选择所有学生姓名。我期望的结果是这样的:
student_name | mark
-------------------
Abi | 9
Bayu | null
Charles | null
我试过这个查询,但它不起作用。我怎样才能做到这一点?
SELECT s.name FROM siswa s LEFT OUTER JOIN nilai n ON s.student_id = n.student_id
WHERE n.semester = '2' AND n.subject = '1'