ON clause
The part of a join that states which rows of the two tables belong together.
In more detail
It usually compares a foreign key with the primary key it points at. A condition in ON that names only one table is a filter, not a pairing rule, and silently pairs every row with every matching row. In an outer join, conditions on the optional table belong in ON, not WHERE.
Related terms
- join — Combining rows from two tables into one result by pairing rows according to a rule, usually matching keys.
- WHERE clause — The part of a query that keeps only the rows for which a condition is true.
- Cartesian product — Every possible pairing of one item from each of two sets, so the number of pairs is the product of the two sizes.
- LEFT JOIN — A join that keeps every row of the left table and adds the matching right-hand rows, or NULLs when there is no match.
Taught in
- Inner Joins And Table Aliases — PostgreSQL, Indexing & Relational Data Modeling
- What An Outer Join Really Returns — PostgreSQL, Indexing & Relational Data Modeling
- Cross Joins And Cartesian Bugs — PostgreSQL, Indexing & Relational Data Modeling