🗃️SQL Join
Also known as JOIN, Table Join
The part of a query that pairs rows from two tables. You get one result.
Think of it like
Think of it like matching socks from two piles. You pair each sock with the one that fits it.
Example
Emma wants each order with the buyer's name. Orders hold only a customer id, so she joins them to customers.
Why it matters
Data is split across tables to keep it clean. Joins put it back together when you need it.
Definition
Example code
sql
SELECT customers.name, orders.total
FROM customers
JOIN orders ON orders.customer_id = customers.id;
-- Emma | 25.0
-- Emma | 40.0
-- Jack | 15.5Common mistake
Key takeaways
- 1Two tables, one answer. Rows are matched side by side.
- 2Match on keys. Most often a foreign key and a primary key.
- 3Kinds of join. Inner keeps matches, left keeps all.