JOINs
What you will learn
How to combine data from multiple tables using JOIN.
INNER JOIN
SELECT users.name, orders.total
FROM users
JOIN orders ON users.id = orders.user_id;
Only rows where the condition matches appear in the result.
LEFT JOIN
SELECT users.name, orders.total
FROM users
LEFT JOIN orders ON users.id = orders.user_id;
All users appear, even those with no orders — total will be NULL.
Common mistakes
- Forgetting the
ONclause — causes a cartesian product (every row × every row) - Mixing up
LEFTandINNER— test with a row that has no match to see the difference
Quick check below!