Lesson 19 / 37 · Joins
Joins chain left to right, one step each
Three joins are three steps. Each takes everything the previous step produced and pairs it with the next table. Watch the row count change at every step.
The query
SELECT c.name, p.name AS product, i.qty
FROM customers c
JOIN orders o ON o.customer_id = c.id
JOIN order_items i ON i.order_id = o.id
JOIN products p ON p.id = i.product_id
WHERE o.status = 'paid'
Try AND i.qty > 1 in WHERE: a filter can test a column of any joined table, and 2 rows remain.
Next: GROUP BY collects rows, then each group becomes one row · All lessons