← ACARA Digital Technologies Years 9–10

A join that forgets the ON condition

A join with no ON condition pairs every row of one table with every row of the other, so 3 customers and 4 orders give 12 rows, most of them wrong.

Understanding A join that forgets the ON condition in ACARA Digital Technologies Years 9–10

What it does: Without ON, the row count is rows x rows. Counting the rows of the unconditioned join shows the multiplication, e.g. 10 students x 10 orders = 100. The ON condition links the foreign key orders.productId to the primary key products.productId, so only matching rows are paired. The first query has no ON condition, so each student row is paired with every results row. A sudden jump in row count is the warning sign of a join with no ON condition. The database does not invent data. Join on the foreign key and the primary key it points to. Quantity and points are unrelated fields, so matches would be meaningless.

Common mistakes: The ON condition compares the customer's id with the order's own id, not the customer it belongs to. The rows are paired on the wrong fields. It should be ON c.id = o.customerId; (primary key = foreign key). This compares the students table with itself, so it is true for every row. Every student is still paired with every order. It should be ON s.studentId = o.studentId; to link students to orders.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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.

Learning
Duo
A query joins a table of 3 customers with a table of 4 orders but has no ON condition. How many rows come back?
12 rows (3 x 4)4 rows (one per order)
Matches
SELECT firstName, name FROM students JOIN products;
↓
The ON condition is missing, so every student is paired with every product and most rows are wrong. Add ON to match the linked fields.
Applying
Meanings
Term
Cartesian product
Meaning
A join with no ON condition pairs every row of one table with every row of the other, so 3 customers and 4 orders give 12 rows, most of them wrong.
Practice
SELECT students.firstName, orders.orderId
Testing
Gaps
students.studentId = orders.studentId;
Check Answer
Spots
3JOIN orders o
4ON c.id = o.orderId;

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Cosmic Owl' badge — Comprehension Guru, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A query joins a table of 3 customers with a table of 4 orders but has no ON condition. How many rows come back?
A. 12 rows (3 x 4) ✓
B. 4 rows (one per order)
With no ON condition, every customer is paired with every order, so you get 3 x 4 = 12 rows.
2. Which query forgets the ON condition?
A. SELECT * FROM students JOIN results ON students.studentId = results.studentId;
B. SELECT * FROM students JOIN results; ✓
The first query has no ON condition, so each student row is paired with every results row.
3. The students table has 10 rows and the results table has 20 rows. A join with no ON condition gives how many rows?
A. 200 rows ✓
B. 20 rows
10 x 20 = 200. Every student is paired with every result, and most of those pairs are wrong.
4. You run a join and get far more rows than the orders table holds. What is the most likely cause?
A. The ON condition is missing, so every row is paired with every other row ✓
B. The database has added extra orders to the data
A sudden jump in row count is the warning sign of a join with no ON condition. The database does not invent data.
5. How do you fix a join that gives too many rows?
A. Add ORDER BY to sort out the extra rows
B. Add ON with the foreign key equal to the primary key ✓
ON orders.studentId = students.studentId keeps only the pairs that really belong together. ORDER BY only changes the order, not the number of rows.

Match the Pairs

SELECT * FROM students JOIN orders; → A join with no ON condition: every student row is paired with every order row, so most result rows are wrong
SELECT * FROM students JOIN orders ON students.studentId = orders.studentId; → A join with an ON condition: only rows where the student IDs match are kept, so each order pairs with its own student
3 customers joined to 4 orders with no ON condition gives 3 x 4 = 12 rows → SELECT COUNT(*) FROM students JOIN orders;
Adding the ON condition stops every row being paired with every other row → FROM orders JOIN products ON orders.productId = products.productId
SELECT firstName, name FROM students JOIN products; → The ON condition is missing, so every student is paired with every product and most rows are wrong. Add ON to match the linked fields.
SELECT * FROM students JOIN orders ON students.points = orders.quantity; → The ON condition joins the wrong fields. It should match students.studentId = orders.studentId (primary key to foreign key).

Key Term

Cartesian product
A join with no ON condition pairs every row of one table with every row of the other, so 3 customers and 4 orders give 12 rows, most of them wrong.

Fill in the Blanks

1. SELECT firstName, orderId FROM students JOIN orders ON students.studentId = orders.studentId;
Hint: Type the keyword that starts the matching condition in a join, so rows are only paired when the fields agree.
2. SELECT * FROM students JOIN orders; -- 3 rows x 4 rows gives 12 rows
Hint: Type the number of rows you get by multiplying the row counts of the two tables.
3. SELECT name, quantity FROM products JOIN orders ON products.productId = orders.productId;
Hint: Type the foreign key field in orders that links back to the products table.
4. SELECT name, mark FROM results JOIN subjects ON results.subjectId = subjects.subjectId;
Hint: Type the table name that holds the foreign key field being matched.
5. SELECT COUNT(*) FROM students JOIN orders; -- no ON, so every pairing is counted
Hint: Type the aggregate function that counts rows, which shows far too many rows when the ON condition is missing.

Spot the Error

Question 1
A SELECT c.name, o.orderId
B FROM customers c
C JOIN orders o
D ON c.id = o.orderId;
Line D — The ON condition compares the customer's id with the order's own id, not the customer it belongs to. The rows are paired on the wrong fields. It should be ON c.id = o.customerId; (primary key = foreign key).
Question 2
A SELECT s.firstName, o.orderId
B FROM students s
C JOIN orders o
D ON s.studentId = s.studentId;
Line D — This compares the students table with itself, so it is true for every row. Every student is still paired with every order. It should be ON s.studentId = o.studentId; to link students to orders.
Question 3
A -- 3 customers, 4 orders
B -- No ON: 3 + 4 = 7 rows
C SELECT c.name, o.orderId
D FROM customers c JOIN orders o
E ON c.id = o.customerId;
Line B — Without an ON condition, every customer is paired with every order, so the rows are multiplied, not added. 3 x 4 = 12 rows, not 7.
Question 4
A -- 3 customers, 4 orders
B -- No ON: only matches pair up
C SELECT c.name, o.orderId
D FROM customers c JOIN orders o
E ON c.id = o.customerId;
Line B — With no ON condition nothing filters the pairs, so every row pairs with every row, matching or not. Only the ON condition keeps just the matching rows.
Question 5
A -- Too many rows? Drop the ON
B SELECT c.name, o.orderId
C FROM customers c JOIN orders o
D ON c.id = o.customerId;
Line A — Too many rows means the join has no matching condition. The fix is to add the ON condition, not to remove it. Dropping it would give 3 x 4 = 12 rows again.

Student with a class code? Join your class →