An INNER JOIN drops rows with no match. Outer joins keep them: a LEFT JOIN keeps every row from the left table, filling missing right-side columns with NULL.
LEFT JOIN
SELECT s.name, p.name AS programmeFROM students sLEFT JOIN programmes p ON s.programme_id = p.id;-- students with no programme still appear, with NULL programme
Finding non-matches
A powerful pattern: LEFT JOIN then keep only the NULL side to find rows with no match:
SELECT s.nameFROM students sLEFT JOIN programmes p ON s.programme_id = p.idWHERE p.id IS NULL;
Key takeaways
- 01A LEFT JOIN keeps all rows from the left table, NULL-filling unmatched right columns.
- 02RIGHT JOIN is the mirror (keep all right rows) — usually rewritten as a LEFT JOIN.
- 03LEFT JOIN … WHERE right_key IS NULL finds rows with no match (anti-join).
- 04Outer joins are how you keep, rather than drop, unmatched rows.
