SQL Joins
Related information usually lives in separate tables. A join connects rows using a relationship, such as an order's customer_id and the matching customer's primary key. It lets a report show useful names without storing the same name on every order.
Understand the idea
Start by naming the grain of the result: one row per order in this example. The ON condition matches identifiers rather than names, because names can change or be shared by different people. An inner join returns only matching pairs. Later lessons use outer joins to preserve rows that have no match.
Where to try it
Run this example in the SQL playground. The lesson link loads the shop tables and sample rows before this query. Select Run when you are ready. Every run starts fresh, so your changes do not affect the website or a previous run.
SQLite sample data · MySQL / MariaDB sample data · See the sample tables
A worked example
SELECT o.order_id, c.name, o.status
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
ORDER BY o.order_id;
Read the result
There are four result rows. Mira appears on two orders because she placed orders 101 and 103. Repeated customer names are expected at the order grain; they do not mean the join is broken.
Try one change
Add total_cents to the result. Explain why the customer name repeats while each order_id remains unique.