CROSS JOIN
CROSS JOIN creates every possible pair of rows
CROSS JOIN does not look for matches by key. It combines every row from the first set with every row from the second.
SELECT c.name, s.size
FROM colors AS c
CROSS JOIN sizes AS s;
If colors contains 3 rows and sizes contains 4, the result contains 12 combinations.
When a Cartesian product is useful
This kind of join is useful when every combination is meaningful: for example, when building a “plan × region” matrix or a set of “color × size” variants.
The result size grows very quickly.
With 10,000 rows in one table and 10,000 in another, a CROSS JOIN can potentially produce 100 million combinations. Use it only when a Cartesian product is actually required.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in