A CROSS JOIN produces the Cartesian product of two tables — every row from the first table is combined with every row from the second table. No ON condition is required or used. If the first table has 4 rows and the second has 3 rows, the result has 4 × 3 = 12 rows.
Unlike other joins, CROSS JOIN does not look for matching values — it blindly combines everything with everything.
SELECT columns
FROM table_a
CROSS JOIN table_b;
No ON clause is needed — or allowed — because there is no matching condition.
Imagine two small tables — one for colours and one for sizes:
colours
| colour |
|---|
| Red |
| Blue |
| Green |
sizes
| size |
|---|
| S |
| M |
| L |
SELECT colour, size
FROM colours
CROSS JOIN sizes;
| colour | size |
|---|---|
| Red | S |
| Red | M |
| Red | L |
| Blue | S |
| Blue | M |
| Blue | L |
| Green | S |
| Green | M |
| Green | L |
3 colours × 3 sizes = 9 rows. Every possible combination is generated.
CROSS JOIN is useful in specific scenarios where you genuinely need all combinations:
CROSS JOIN on large tables can produce enormous result sets very quickly. Joining a table with 1,000 rows to another with 1,000 rows produces 1,000,000 rows. Always be aware of table sizes before using CROSS JOIN in production queries.
You can add a WHERE clause to filter the Cartesian product down to only the combinations you need:
-- Only Blue combinations
SELECT colour, size
FROM colours
CROSS JOIN sizes
WHERE colour = 'Blue';
ON or WHERE condition that matches rows between the two tables effectively turns a CROSS JOIN into an INNER JOIN. If you need a matching condition, use INNER JOIN explicitly — it is clearer in intent.
CROSS JOIN produces the Cartesian product — every row from table A paired with every row from table B.ON clause is used — there is no matching condition.