JOIN ON Clause
Question
What does the ON clause specify in a JOIN?
Hint
ON defines how tables are related in the join.
Explanation
The ON clause specifies the condition for matching rows between the joined tables. SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id matches orders to customers where the customer_id matches. ON typically uses equality on key columns (foreign key = primary key), but can use any condition. Multiple conditions: ON o.customer_id = c.id AND o.status = "active". Without ON (cross join), every row is combined with every other row (Cartesian product). The ON condition determines which rows from each table are combined.
Related Resources
Related Lessons
- JOINs
Learn JOINs.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.