MEPX
Chapter 6 of 10All chapters

Chapter 6 of 10

Joins

Combining rows from two tables.

The four you need

INNER JOIN keeps rows with a match on both sides. LEFT JOIN keeps every left row and fills missing right columns with NULL. RIGHT is the mirror, and FULL keeps both.

  • The ON clause says which columns must line up.
  • A missing ON clause produces a cross join, every row against every row.

Finding what is missing

A LEFT JOIN with WHERE right.id IS NULL returns rows that have no match, which is how you find customers with no orders or records with a broken reference.