Joining Tables
Once data is split across tables, a join puts it back together in a query. JOIN ... ON matches rows using the key columns.
- INNER JOIN (the default
JOIN) keeps only rows that match on both sides. - LEFT JOIN keeps every row from the left table, with
NULLwhere nothing matches. Use it to find things with no match, such as customers who never ordered.
Give each table a short alias (c, o) and prefix columns with it, so it is clear where each comes from.
Examplepython
Quick check
Which join keeps all rows of the left table even with no match?
Your turn: write the code
Print the names of customers who have no orders (use a LEFT JOIN and WHERE o.id IS NULL), as a list of names.
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.