SQL JOIN across two tables
Combines rows from two tables where a foreign key matches a primary key, so related data shows in one result. Use table.field names to say which table each field belongs to.
Understanding SQL JOIN across two tables in VCE Spreadsheets, SQL & Visualisation
What it does: The query joins Students to Classes using class_id, so each student name appears beside the class_name from the other table. Both tables have a customer_id field, so the table name before the dot makes it clear which one is meant. INNER JOIN needs an ON condition that matches a foreign key to a primary key, written as table.field = table.field. ON gives the matching rule, such as orders.customer_id = customers.customer_id. ORDER BY is what sorts rows. A JOIN does not change the tables. It combines related records into a single result you can read. The ON keyword is required before the matching condition. Without it the query will not run.
Common mistakes: Both tables have a field called name, so a plain name is ambiguous. Use table.field names to say which table each field comes from: SELECT pet.name, owner.name. The ON line must match the foreign key to the primary key of the other table. team.city is not the key. It should be ON player.team_id = team.id.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 55–70) and word search (Modules 55–86).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
INNER JOIN t2 ON t1.key = t2.keyFill in the Blanks
Spot the Error
Student with a class code? Join your class →