Monday, November 30, 2009

Cross Join in SQL

SQL CROSS JOIN will return all records where each row from the first table is combined with each row from the second table. Which also mean CROSS JOIN returns the Cartesian product of the sets of rows from the joined tables.
in other meaning Cross Joins produce results that consist of every combination of rows from two or more tables That means if table A has 3 rows and table B has 2 rows, a CROSS JOIN will result in 6 rows.  There is no relationship established between the two tables – you literally just produce every possible combination.


it is useful if you do lots of report writing in SQL, a CROSS JOIN can be your best friend.
you can create Cross join in two ways 
1. using join keyword 
2. list all the tables in the from clause separated by comma without using where 







No comments:

Post a Comment