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,
ID | NAME |
---|---|
1 | abhi |
2 | adam |
4 | alex |
The class_info table,
ID | Address |
---|---|
1 | DELHI |
2 | MUMBAI |
3 | CHENNAI |
Cross JOIN query will be,
SELECT * from class, cross JOIN class_info;
The result table will look like,
ID | NAME | ID | Address |
---|---|---|---|
1 | abhi | 1 | DELHI |
2 | adam | 1 | DELHI |
4 | alex | 1 | DELHI |
1 | abhi | 2 | MUMBAI |
2 | adam | 2 | MUMBAI |
4 | alex | 2 | MUMBAI |
1 | abhi | 3 | CHENNAI |
2 | adam | 3 | CHENNAI |
4 | alex | 3 | CHENNAI |
No comments:
Post a Comment