What is the difference between Left, Right, Outer and Inner Joins?

后端 未结 9 1620
刺人心
刺人心 2020-11-22 07:10

I am wondering how to differentiate all these different joins ...

9条回答
  •  醉话见心
    2020-11-22 07:53

    There are only 4 kinds:

    1. Inner join: The most common type. An output row is produced for every pair of input rows that match on the join conditions.
    2. Left outer join: The same as an inner join, except that if there is any row for which no matching row in the table on the right can be found, a row is output containing the values from the table on the left, with NULL for each value in the table on the right. This means that every row from the table on the left will appear at least once in the output.
    3. Right outer join: The same as a left outer join, except with the roles of the tables reversed.
    4. Full outer join: A combination of left and right outer joins. Every row from both tables will appear in the output at least once.

    A "cross join" or "cartesian join" is simply an inner join for which no join conditions have been specified, resulting in all pairs of rows being output.

    Thanks to RusselH for pointing out FULL joins, which I'd omitted.

提交回复
热议问题