Module 5: Joins

Combine tables: inner and outer joins, self joins, and finding the rows that have no match.

  1. INNER JOIN: matching rows across tables: JOIN t ON key = key keeps only matching pairs: rows with no match, or a NULL key, disappear.
  2. LEFT, RIGHT and FULL joins: keeping rows with no match: LEFT JOIN keeps every left row; WHERE right.pk IS NULL finds rows with no match; filters on the right table go in ON.
  3. SELF and CROSS joins: A self join uses one table in two roles (c and r); CROSS JOIN makes every pair, m × n rows.
  4. Joins with GROUP BY, and the double-counting trap: Count the right table with COUNT(right.pk); a one-to-many join repeats parent rows, so sum parent columns before joining.

Ends with a 12-question checkpoint (80% passes) and a project: The restaurant scorecard.