A CROSS JOIN returns the Cartesian product of two tables. Every row from the first table is combined with every row from the second table.
CROSS JOIN is useful when you intentionally need every possible combination of two sets of data.
Create every possible combination of products and store locations.
SELECT
p.ProductName,
s.StoreName
FROM Products p
CROSS JOIN Stores s;
CROSS JOIN can be used for planning scenarios, product combinations, schedules, testing datasets, and pricing analysis.
- CROSS JOIN creates every possible combination.
- It does not require an ON condition.
- The result can become very large.
- It is useful for generating combinations.
- Use it carefully with large tables.
What does CROSS JOIN do?
CROSS JOIN combines every row from the first table with every row from the second table.
Does CROSS JOIN require an ON condition?
No. CROSS JOIN does not require a join condition.