一张图看懂 SQL 的各种 join 用法

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

具体分解如下:
1.INNER JOIN(内连接)

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

2.LEFT JOIN(左连接)

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

3.RIGHT JOIN(右连接)

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

4.OUTER JOIN(外连接)

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

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

SELECT<select_list>
FROM Table_A A
LEFTJOIN Table_B B
ON A.Key = B.Key
WHERE B.KeyISNULL

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

SELECT<select_list>
FROM Table_A A
RIGHTJOIN Table_B B
ON A.Key = B.Key
WHERE A.KeyISNULL

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

SELECT<select_list>
FROM Table_A A
FULLOUTERJOIN Table_B B
ON A.Key = B.Key
WHERE A.KeyISNULLOR B.KeyISNULL
本站所有文章均由网友分享,仅用于参考学习用,请勿直接转载,如有侵权,请联系网站客服删除相关文章。若由于商用引起版权纠纷,一切责任均由使用者承担
极客文库 » 一张图看懂 SQL 的各种 join 用法

Leave a Reply

欢迎加入「极客文库」,成为原创作者从这里开始!

立即加入 了解更多