SQL JOIN (INNER JOIN)
A JOIN combines rows from two tables using a matching column, usually an id. JOIN on its own means INNER JOIN: it keeps only rows that have a match on both sides.
Updated December 1, 2026
Syntax
SELECT a.column, b.column
FROM table_a AS a
JOIN table_b AS b ON b.id = a.b_id;
Join two tables
Each order stores a customer_id. Joining to customers swaps that id for a name.
SELECT o.id, c.name, o.quantity
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id
ORDER BY o.id;
| id | name | quantity |
|---|---|---|
| 1 | Ava | 1 |
| 2 | Ava | 2 |
| 3 | Ben | 1 |
| 4 | Cara | 1 |
| 5 | Dev | 3 |
| 6 | Eli | 1 |
Join three tables
Add another JOIN for each table. Now every order shows who bought what.
SELECT o.id, c.name AS customer, d.name AS drink
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id
JOIN drinks AS d ON d.id = o.drink_id
ORDER BY o.id;
| id | customer | drink |
|---|---|---|
| 1 | Ava | Latte |
| 2 | Ava | Hot Chocolate |
| 3 | Ben | Cold Brew |
| 4 | Cara | Matcha Latte |
| 5 | Dev | Espresso |
| 6 | Eli | Latte |
Types of join
- INNER JOIN keeps rows that match in both tables.
- LEFT JOIN keeps every row from the left table, with NULLs where nothing matches.
- RIGHT JOIN is the mirror image of LEFT JOIN.
- FULL OUTER JOIN keeps unmatched rows from both sides.
- CROSS JOIN pairs every row with every row.
Common mistakes
- Forgetting the
ONcondition, which pairs every row with every row (a cross join) and multiplies the result. - Joining on the wrong columns, such as
c.id = o.idinstead ofc.id = o.customer_id. - Ambiguous column names: when both tables have
nameorid, prefix them with the table alias.
Practice JOIN (INNER JOIN) interactively
Write real queries in your browser and get instant feedback in the lesson “INNER JOIN” (Unit 5). New learners can start free from the first lesson.
Frequently asked questions
Is JOIN the same as INNER JOIN?
Yes. INNER is optional.
Why did my join return more rows than expected?
One row matched several rows on the other side (a one-to-many relationship). That’s often correct; if not, check your ON condition or aggregate first.