且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server 中的 LEFT JOIN 与 LEFT OUTER JOIN

更新时间:2022-11-04 16:28:36

根据文档:FROM (Transact-SQL):

<join_type> ::= 
    [ { INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } } [ <join_hint> ] ]
    JOIN

关键字OUTER 被标记为可选(括在方括号中).在这种特定情况下,是否指定 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.

例如,JOIN 子句的整个类型部分是可选的,在这种情况下,如果您只指定 JOIN,则默认为 INNER>.换句话说,这是合法的:

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

还要看看我在另一个 SO 问题上留下的答案:SQL 左连接与 FROM 行上的多个表?一>.

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