×

sql · level 2 · unit 3 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

keeps every row from the first table.

A plain JOIN drops rows that find no match, so Nibbles vanished. Sometimes that hides the most important row. LEFT JOIN keeps every row from the : the one written first.

When a left row finds no match, it stays anyway, and every column from the other table is NULL. Nibbles comes back, with NULL for the owner.

Which table goes first matters. pets LEFT JOIN owners keeps every pet. owners LEFT JOIN pets keeps every owner, Dev included.

SELECT p.name AS pet, o.name AS owner
FROM pets p
LEFT JOIN owners o ON p.owner_id = o.id;

Only the left table is kept whole. Here Dev, an owner with no pets, still vanishes.