zoukankan      html  css  js  c++  java
  • LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

    LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

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

    <join_type> ::= 
        [ { INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } } [ <join_hint> ] ]
        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?.

    需要注意下面的图的数据,a和b的交集,可能会超出想象。

    a left join b,a里面一条数据可能对应b里面的两条数据,甚至3条数据

  • 相关阅读:
    4.26上午
    4.25下午
    4.19上午
    4.18上午
    7.26
    7.25
    7.21-7.22
    7.22
    7.21
    7.11-7.15
  • 原文地址:https://www.cnblogs.com/chucklu/p/14469711.html
Copyright © 2011-2022 走看看