Joining three tables
A second JOIN line chained after the first to reach a third table. It follows a foreign key in the junction table to the primary key of the next table.
Understanding Joining three tables in ACARA Digital Technologies Years 9–10
What it does: This FROM clause has two JOIN ... ON lines, so it links students to results and then results to subjects. Each JOIN adds one more table to the first. Two JOIN lines link three tables. Follow the foreign key subjectId in results to the primary key subjectId in subjects. studentId and subjectId are different keys and must not be matched. orders.productId is the foreign key that points to products.productId. orders.studentId points to students instead. Without an ON condition, the rows are not matched up by keys. You get every possible pairing, which is wrong. studentId appears in more than one table, so qualify it with the table name. Otherwise SQL reports an ambiguous column.
Common mistakes: The table is called students, not student. The FROM line must use the real table name, then the alias s. The junction table is orders, not order. It should be JOIN orders o so the first JOIN can link students to it.
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 459–475) and word search (Modules 459–534).
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
JOIN subjects ON results.subjectId = subjects.subjectIdFill in the Blanks
Spot the Error
Student with a class code? Join your class →