Writing the ON condition: foreign key equals primary key
The join condition: it matches the foreign key in one table to the primary key in the other. The = sign compares the two values to find matching rows. It does not assign a value.
Understanding Writing the ON condition: foreign key equals primary key in ACARA Digital Technologies Years 9–10
What it does: orders.customer_id is the foreign key and customers.customer_id is the primary key. The ON condition sets them equal to match rows. In a join, = is a comparison. Rows are matched when the two values are equal. Nothing is stored or changed. Both tables have a field called customer_id, so you must put the table name before each field. Otherwise SQL cannot tell which one you mean. SQL uses a single = to compare values. Double equals (==) is used in some other languages, but it is a syntax error in SQL. Equals works both ways, so the matched rows are the same. Writing the foreign key first is just a common habit that makes the link easier to read.
Common mistakes: orders.order_id is the primary key of orders, not the foreign key. The ON condition must compare the foreign key orders.customer_id with customers.customer_id. SQL compares values with a single = sign. Double == is not valid in the ON condition. It should be = orders.customer_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 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
ON orders.customer_id = customers.customer_idFill in the Blanks
Spot the Error
Student with a class code? Join your class →