What is a CROSS JOIN and when would you actually use one?
SQLLevel: FoundationJOINs Basics
What is a CROSS JOIN and when would you actually use one?
Hints
- Write the join keys and relationship cardinality.
- What happens to duplicates and unmatched rows? Check WHERE versus ON.
Answer
A CROSS JOIN produces the Cartesian product — every row from the left table paired with every row from the right table. No join condition.
-- All combinations of sizes and colors
SELECT s.size_name, c.color_name
FROM sizes s
CROSS JOIN colors c;
Real use cases:
- Generating all date/time combinations (e.g., every hour x every day)
- Creating a "calendar" table by crossing a numbers table with date logic
- Generating all possible combinations for a product configurator
Source and licence: SQL Interview Questions — Arda Kocadoru · MIT