Joining three tables in SQL
Joins chain: each new table joins whatever has been assembled so far.
SELECT
o.id AS order_id,
c.name AS customer,
p.name AS product,
i.quantity
FROM orders AS o
JOIN customers AS c
ON c.id = o.customer_id
JOIN order_items AS i
ON i.order_id = o.id
JOIN products AS p
ON p.sku = i.sku
WHERE o.placed_at >= '2026-07-01';
How it works
- Join order follows the relationships, not the SELECT list.
- Each
ONclause connects one new table to the rows before it. - Filters on the joined tables belong in
WHERE.
Keywords and builtins used here
ASFROMJOINONSELECTWHEREc
The run, in numbers
- Lines
- 13
- Characters to type
- 249
- Tokens
- 70
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 49 seconds.
Step 7 of 9 in Joins, step 15 of 22 in Joins & aggregation.