SQL Server: What is the difference between CROSS J

2019-01-10 05:21发布

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?

10条回答
我只想做你的唯一
2楼-- · 2019-01-10 05:56

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

  • SQL full outer join is also known as FULL 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/

查看更多
闹够了就滚
3楼-- · 2019-01-10 05:58

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)

查看更多
放荡不羁爱自由
4楼-- · 2019-01-10 06:05

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

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-10 06:07

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.

查看更多
登录 后发表回答