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?
For SQL Server, CROSS JOIN and FULL OUTER JOIN are different.
CROSS JOIN is simply Cartesian Product of two tables, irrespective of any filter criteria or any condition.
FULL OUTER JOIN gives unique result set of LEFT OUTER JOIN and RIGHT OUTER JOIN of two tables. It also needs ON clause to map two columns of tables.
Table 1 contains 10 rows and Table 2 contains 20 rows with 5 rows matching on specific columns.
Then
CROSS JOINwill return 10*20=200 rows in result set.
FULL OUTER JOINwill return 25 rows in result set.
FULL OUTER JOIN(or any other JOIN) always returns result set with less than or equal toCartesian Product number.Number of rows returned by
FULL OUTER JOINequal to (No. of Rows byLEFT OUTER JOIN) + (No. of Rows byRIGHT OUTER JOIN) - (No. of Rows byINNER JOIN).