LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

后端 未结 12 1895
失恋的感觉
失恋的感觉 2020-11-21 13:25

What is the difference between LEFT JOIN and LEFT OUTER JOIN?

12条回答
  •  执笔经年
    2020-11-21 13:43

    Why are LEFT/RIGHT and LEFT OUTER/RIGHT OUTER the same? Let's explain why this vocabulary. Understand that LEFT and RIGHT joins are specific cases of the OUTER join, and therefore couldn't be anything else than OUTER LEFT/OUTER RIGHT. The OUTER join is also called FULL OUTER as opposed to LEFT and RIGHT joins that are PARTIAL results of the OUTER join. Indeed:

    Table A | Table B     Table A | Table B      Table A | Table B      Table A | Table B
       1    |   5            1    |   1             1    |   1             1    |   1
       2    |   1            2    |   2             2    |   2             2    |   2
       3    |   6            3    |  null           3    |  null           -    |   -
       4    |   2            4    |  null           4    |  null           -    |   -
                            null  |   5             -    |   -            null  |   5
                            null  |   6             -    |   -            null  |   6
    
                          OUTER JOIN (FULL)     LEFT OUTER (partial)   RIGHT OUTER (partial)
    

    It is now clear why those operations have aliases, as well as it is clear only 3 cases exist: INNER, OUTER, CROSS. With two sub-cases for the OUTER. The vocabulary, the way teachers explain this, as well as some answers above, often make it looks like there are lots of different types of join. But it's actually very simple.

提交回复
热议问题