In brief
The lesson explains how SQL table joins work. INNER JOIN keeps only matching pairs, LEFT JOIN preserves every row from the left table, and FULL JOIN preserves rows from both sides. The main mistakes are filtering the right table in WHERE after a LEFT JOIN and multiplying rows because the join key is not unique.
Key points
- JOIN combines rows from two tables using a condition in ON.
- INNER JOIN returns only rows that have a matching pair.
- LEFT JOIN keeps every row on the left; missing matches become NULL.
- A WHERE condition on the right table can turn a LEFT JOIN into an INNER JOIN.
- FULL JOIN keeps rows from both tables.
- A non-unique key on the right multiplies rows on the left — compare row counts before and after.
- An anti-join — LEFT JOIN … WHERE right.id IS NULL — finds rows without a match.
Chapters
- Why tables need joins
- INNER JOIN
- LEFT and RIGHT JOIN
- FULL JOIN
- Row multiplication
- Finding rows without a match
Terms
- Join key
- The columns used to compare rows in the ON condition.
- LEFT JOIN
- A join that preserves every row from the left table.
- Anti-join
- A query that returns rows with no match in another table.
Takeaways
- Put filters on the right table in ON when you need LEFT JOIN semantics.
- Count rows before and after a join.
- To find “no match” rows, use LEFT JOIN + IS NULL or NOT EXISTS.
Check yourself
Questions about the video
How do I find customers with no orders?
LEFT JOIN orders to customers and filter with WHERE orders.id IS NULL . NOT EXISTS is an equivalent approach.
Why did my LEFT JOIN lose rows?
A condition on the right table is probably in WHERE. Move that condition into ON .