How to use JOIN in mysql to display all data that does not match

I want to show data from 2 tables, and I want to show all of them, including data that does not match. I tried with this request.

SELECT * FROM student s
LEFT JOIN grade g ON g.student_id=s.student_id
WHERE s.student_id = 9

What I get is only showing students with a degree, while what I need shows all students, even if they don’t have a grade. I also tried to use inner join, right joinbut the same result. What should be the request?

+6
source share
2 answers

WHERE s.student_id = 9, ( ) s.student_id null, where student_id, null 9 .

where join:

SELECT * 
FROM student s
LEFT JOIN grade g ON g.student_id=s.student_id AND s.student_id = 9;

NOT IN:

SELECT * 
FROM student s
WHERE s.student_id = 9
  AND student_id NOT IN(SELECT student_id 
                        from grade 
                        where student_id is not null);
+7

, , , , SQL JOIN. , , .

:

SELECT * FROM student s

LEFT JOIN grade g ON g.student_id = s.student_id

WHERE s.student_id = 9

:

,

:

" , , , 9 "

quastion , : Grade?

, WHERE , ID = 9, ( @Brittain Ze IN)

( , , ), SELECT * FROM Student WHERE student_id = 9 . , .

+1

All Articles