LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

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

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

12条回答
  •  你的背包
    2020-11-21 13:43

    As per the documentation: FROM (Transact-SQL):

     ::= 
        [ { INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } } [  ] ]
        JOIN
    

    The keyword OUTER is marked as optional (enclosed in square brackets). In this specific case, whether you specify OUTER or not makes no difference. Note that while the other elements of the join clause is also marked as optional, leaving them out will make a difference.

    For instance, the entire type-part of the JOIN clause is optional, in which case the default is INNER if you just specify JOIN. In other words, this is legal:

    SELECT *
    FROM A JOIN B ON A.X = B.Y
    

    Here's a list of equivalent syntaxes:

    A LEFT JOIN B            A LEFT OUTER JOIN B
    A RIGHT JOIN B           A RIGHT OUTER JOIN B
    A FULL JOIN B            A FULL OUTER JOIN B
    A INNER JOIN B           A JOIN B
    

    Also take a look at the answer I left on this other SO question: SQL left join vs multiple tables on FROM line?.

    enter image description here

提交回复
热议问题