Skip to main content
Albero Academy

LEFT & RIGHT JOIN

Keep unmatched rows from one side, filling gaps with NULL.

Joins & Combining9 min

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

keep all left rows
SELECT s.name, p.name AS programme
FROM students s
LEFT 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:

students with no programme
SELECT s.name
FROM students s
LEFT JOIN programmes p ON s.programme_id = p.id
WHERE p.id IS NULL;

Key takeaways

  1. 01A LEFT JOIN keeps all rows from the left table, NULL-filling unmatched right columns.
  2. 02RIGHT JOIN is the mirror (keep all right rows) — usually rewritten as a LEFT JOIN.
  3. 03LEFT JOIN … WHERE right_key IS NULL finds rows with no match (anti-join).
  4. 04Outer joins are how you keep, rather than drop, unmatched rows.

Finished this chapter?

Mark it complete to track your progress through SQL.