Part 05 / Topic 2 of 9
INNER JOIN
JOIN ... ON pairs each row with every row that matches the condition, and keeps only the pairs:
SELECT o.order_id, c.first_name, o.order_date, o.status
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
ORDER BY o.order_id
LIMIT 4;
order_id | first_name | order_date | status
----------+------------+------------+-----------
1 | Asha | 2025-01-10 | delivered
2 | Ravi | 2025-01-25 | delivered
3 | Asha | 2025-02-14 | delivered
4 | Meera | 2025-02-20 | shipped
(4 rows)
Read the new pieces:
orders AS o— a table alias. With two tables in play, every column should say where it comes from;o.andc.keep that readable. (TheASis optional; the alias isn't, once queries grow.)JOIN ... ON ...— plainJOINmeansINNER JOIN: rows without a partner are dropped.
One customer never ordered (you found them in the Stage 1 project). In this result they simply don't exist — no order row carries their id, so no pair forms. Inner joins answer "show me the matches"; the next section is for when the non-matches matter.
🧪 Quick quiz — answer from memory, then check.
- What happens to a
customersrow with no matching order in an INNER JOIN? - Why alias tables in a join?
Show the answers
- It's absent from the result — inner joins keep only matched pairs.
- So every column reference says which table it came from — shorter to type, impossible to misread, and required when both tables share a column name.
Done here? The practice set for Part 5 — 8 exercises with solutions — is on the part page.