Orders and customers live in two tables.0 pages read · 0 rows read
Chapter 6 of 7
Joining tables
Each morning the warehouse prints today’s orders with each customer’s details, which live in a separate customers table.
This chapter: How does the database pair each order with its customer?
About this chapter
You will learn
- A join pairs rows from two tables
- A nested loop looks up once per outer row
- Why that lookup is the one to index
Words you’ll meet
- Join
- Pairing rows from two tables that share a value, like an order and its customer.
- Nested loop
- A join that takes each row of one table and looks up its matches in the other.
Step 1 of 4
A pairs rows from two tables. In a , for each of today’s orders the database finds its customer.
Run the join.
The SQL
SELECT o.*, c.*
FROM orders o JOIN customers c ON c.id = o.customer
WHERE o.day = DATE '2026-01-01' + 296;