1 May 2014

Cross Join -- Sql server


A cross join that does not have a WHERE clause produces the Cartesian product of the tables participating in the join.  Result of Cross Join is like Cartesian product of the number of rows in the first table multiplied by the number of rows in the second table i.e. each row from the first table is combined with each row from the second table. 

This join is a Cartesian join that does not necessitate any condition to join. The result set contains records that are multiplication of record number from both the tables.

A cross join returns all possible combinations of all rows from both the tables. So basically it is like joining everything to everything.


 Example for Cross Join or Cartesian Product

Consider Employee Table
Consider Department table
                                              

Query  for cross join :

SELECT  * FROM EmDetails CROSS JOIN Tb_Dept
SELECT * FROM EmDetails , Tb_Dept

Output:





No comments:

Post a Comment