Rows from two tables, matched up
JOIN combines rows from two tables where a condition holds, usually one table's foreign key equals the other's id.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Normalised data keeps names in one table and events in another. Reports need both.
How to think about it
Which column in each table matches? Name both tables, give each an alias, and write ON with the matching columns. Then select from either side.
Worked example
SELECT f.title, d.nameOne column from each table.
FROM films fThe first table, aliased f.
JOIN directors d ON d.id = f.director_id;The matching rule.
Your turn
Join films to their studio.
FROM films f JOIN studios s ON s.id = f.;
Run a query against real tables
The trap
Forgetting ON, or writing an ON that always holds: every row pairs with every row, and the result explodes.
Practise JOIN on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.