SQL Server Interview Question #66

What is a CROSS JOIN?

Joins, Subqueries, CTEs & Set Operators Mid-Level Intermediate

Quick Interview Answer

CROSS JOIN returns the Cartesian product of two data sources: every row from the first source is paired with every row from the second. If one table has 10 rows and another has 5 rows, the CROSS JOIN produces 50 rows. It is useful for generating combinations, but an accidental Cartesian product can create an extremely large result set.

Detailed Explanation

CROSS JOIN returns the Cartesian product of two data sources: every row from the first source is paired with every row from the second.

If one table has 10 rows and another has 5 rows, the CROSS JOIN produces 50 rows. It is useful for generating combinations, but an accidental Cartesian product can create an extremely large result set.

Code Example

SELECT s.SizeName, c.ColorName
FROM dbo.Sizes AS s
CROSS JOIN dbo.Colors AS c;