且构网

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

在SQL中联接多个表

更新时间:2023-01-22 08:44:58

在联接多个表时,每个联接的输出在逻辑上形成一个虚拟表,该虚拟表将进入下一个联接.

When joining multiple tables the output of each join logically forms a virtual table that goes into the next join.

因此,在您所提问的示例中,连接前5个表的综合结果将被视为左侧表.

So in the example in your question the composite result of joining the first 5 tables would be treated as the left hand table.

有关更多信息,请参见 Itzik Ben-Gan的逻辑查询处理海报对这个.

See Itzik Ben-Gan's Logical Query Processing Poster for more about this.

可以通过放置ON子句来控制联接中涉及的虚拟表.例如

The virtual tables involved in the joins can be controlled by positioning the ON clause. For example

SELECT *
FROM   T1
       INNER JOIN T2
         ON T2.C = T1.C
       INNER JOIN T3
                  LEFT JOIN T4
                    ON T4.C = T3.C
         ON T3.C = T2.C 

等同于(T1 Inner Join T2) Inner Join (T3 Left Join T4)