Left Join
LEFT JOIN (LEFT OUTER JOIN) keeps every row from the left table. If the right side has no match, right columns are NULL. FROM students s LEFT JOIN marks m ON s.roll = m.roll; — Kabir still appears with NULL score if he has no marks row.
This is the ‘list all students and their marks if any’ query. Filter ‘students without marks’ with WHERE m.roll IS NULL (anti-join).
Putting WHERE m.score > 50 on a LEFT JOIN turns it into an INNER JOIN for practical purposes — you filtered out the NULLs. Use AND in the ON clause if you must filter the right table but keep left rows.
Trap — WHERE on the right table after LEFT JOIN. Trap: RIGHT JOIN when swapping table order + LEFT would be simpler.
On the example next to this theory — Left Join — jOIN combines rows using a match condition between tables.
students.id
=
marks.student_id
│
▼
one result rowLEFT JOIN marks — students without marks still show, score NULL.