SQL JOIN CROSS JOIN

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Cross join does a Cartesian product of the two members, A Cartesian product means each row of one table is combined with each row of the second table in the join. For example, if TABLEA has 20 rows and TABLEB has 20 rows, the result would be 20*20 = 400 output rows.

Using example database

SELECT d.Name, e.FName
FROM   Departments d
CROSS JOIN Employees e;

Which returns:

d.Namee.FName
HRJames
HRJohn
HRMichael
HRJohnathon
SalesJames
SalesJohn
SalesMichael
SalesJohnathon
TechJames
TechJohn
TechMichael
TechJohnathon

It is recommended to write an explicit CROSS JOIN if you want to do a cartesian join, to highlight that this is what you want.



Got any SQL Question?