SQL Server: What is the difference between CROSS JOIN and FULL OUTER JOIN?

前端 未结 10 1552
星月不相逢
星月不相逢 2020-11-28 18:38

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条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 19:09

    A cross join produces a cartesian product between the two tables, returning all possible combinations of all rows. It has no on clause because you're just joining everything to everything.

    A full outer join is a combination of a left outer and right outer join. It returns all rows in both tables that match the query's where clause, and in cases where the on condition can't be satisfied for those rows it puts null values in for the unpopulated fields.

    This wikipedia article explains the various types of joins with examples of output given a sample set of tables.

提交回复
热议问题