What is the difference between CROSS JOIN and FULL OUTER JOIN in SQL Server?
Are they the same, or not? Please explain. When would one use either of these?
What is the difference between CROSS JOIN and FULL OUTER JOIN in SQL Server?
Are they the same, or not? Please explain. When would one use either of these?
SQL FULL OUTER JOIN
The FULL OUTER JOIN returns all rows from the left table (table1) and from the right table (table2) irrespective of the match.
The FULL OUTER JOIN keyword combines the result of both LEFT OUTER JOIN and RIGHT OUTER JOIN
Reference : http://datasciencemadesimple.com/sql-full-outer-join/
SQL CROSS JOIN
In SQL CROSS JOIN Each Row of first table is mapped with the each and every row of second table.
Number of rows produced by a result set of CROSS JOIN operation is equal to number of rows in the first table multiplied by the number of rows in the second table.
CROSS JOIN is also known as Cartesian product / Cartesian join
Number of rows in table A is m, Number of rows in table B is n and resultant table will have m*n rows
Reference:http://datasciencemadesimple.com/sql-cross-join/
Full outer join :
This join combines left outer join and right outer join. It returns row from either table when the conditions are met and returns null value when there is no match.
image : (http://www.pinaldave.com/bimg/March09UG/outer%20join.jpg)
Cross Join :
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.
image : (http://www.pinaldave.com/bimg/March09UG/cross%20join%20-%20half.jpg)
Cross Join: http://www.dba-oracle.com/t_garmany_9_sql_cross_join.htm
TLDR: Generates a all possible combinations between 2 tables (Carthesian product)
(Full) Outer Join : http://www.w3schools.com/Sql/sql_join_full.asp
TLDR: Returns every row in bot tables and matches those results that have the same values
One thing that might not always be obvious to some is that a cross join with an empty table (or result set) results in empty table (M x N; hence M x 0 = 0)
A full outer join will always have rows unless both M and N are 0.