CROSS JOIN in SQL
Every row on the left paired with every row on the right — on purpose, this time.
SELECT
c.name,
p.sku,
p.price
FROM customers AS c
CROSS JOIN products AS p
ORDER BY c.name, p.sku;
How it works
- A
CROSS JOINhas noONclause: the result is n * m rows. - It is the honest way to build a grid of every combination.
- A
JOINwhoseONyou forgot is the same thing by accident.
Keywords and builtins used here
ASBYCROSSFROMJOINORDERSELECTc
The run, in numbers
- Lines
- 7
- Characters to type
- 98
- Tokens
- 31
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 22 seconds.
Step 5 of 9 in Joins, step 13 of 22 in Joins & aggregation.