sql怎样连接join(一张图看懂SQL的各种)

作者:C.L. Moffatthttp://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

下图展示了 LEFT JOIN、RIGHT JOIN、INNER JOIN、OUTER JOIN 相关的 7 种用法。

sql怎样连接join(一张图看懂SQL的各种)(1)

具体分解如下:

1.INNER JOIN(内连接)

sql怎样连接join(一张图看懂SQL的各种)(2)

SELECT <select_list> FROM Table_A A INNER JOIN Table_B B ON A.Key = B.Key

2.LEFT JOIN(左连接)

sql怎样连接join(一张图看懂SQL的各种)(3)

SELECT <select_list> FROM Table_A A LEFT JOIN Table_B B ON A.Key = B.Key

3.RIGHT JOIN(右连接)

sql怎样连接join(一张图看懂SQL的各种)(4)

SELECT <select_list> FROM Table_A A RIGHT JOIN Table_B B ON A.Key = B.Key

4.OUTER JOIN(外连接)

sql怎样连接join(一张图看懂SQL的各种)(5)

SELECT <select_list> FROM Table_A A FULL OUTER JOIN Table_B B ON A.Key = B.Key

5.LEFT JOIN EXCLUDING INNER JOIN(左连接-内连接)

sql怎样连接join(一张图看懂SQL的各种)(6)

SELECT <select_list> FROM Table_A A LEFT JOIN Table_B B ON A.Key = B.Key WHERE B.Key IS NULL

6.RIGHT JOIN EXCLUDING INNER JOIN(右连接-内连接)

sql怎样连接join(一张图看懂SQL的各种)(7)

SELECT <select_list> FROM Table_A A RIGHT JOIN Table_B B ON A.Key = B.Key WHERE A.Key IS NULL

7.OUTER JOIN EXCLUDING INNER JOIN(外连接-内连接)

sql怎样连接join(一张图看懂SQL的各种)(8)

SELECT <select_list> FROM Table_A A FULL OUTER JOIN Table_B B ON A.Key = B.Key WHERE A.Key IS NULL OR B.Key IS NULL

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页