Sunday, May 3, 2015

SQL Cross JOIN or Cartesian Product

This type of JOIN returns the cartesian product of rows of from the tables in Join. It will return a table which consists of records which combines each row from the first table with each row of the second table.
Cross JOIN Syntax is,
SELECT column-name-list
from table-name1 
CROSS JOIN 
table-name2;

Example of Cross JOIN

The class table,
IDNAME
1abhi
2adam
4alex
The class_info table,
IDAddress
1DELHI
2MUMBAI
3CHENNAI
Cross JOIN query will be,
SELECT *
 from class,
 cross JOIN class_info;
The result table will look like,
IDNAMEIDAddress
1abhi1DELHI
2adam1DELHI
4alex1DELHI
1abhi2MUMBAI
2adam2MUMBAI
4alex2MUMBAI
1abhi3CHENNAI
2adam3CHENNAI
4alex3CHENNAI

No comments:

Post a Comment