作者 | C.L. Moffatt
来源 | codeproject
导读:下图展示了 LEFT JOIN、RIGHT JOIN、INNER JOIN、OUTER JOIN 相关的 7 种用法。
www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
具体分解如下:
1.INNER JOIN(内连接)
SELECT <select_list>
FROM Table_A A
INNER JOIN Table_B B
ON A.Key = B.Key
2.LEFT JOIN
(左连接)
SELECT <select_list>
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key
3.RIGHT JOIN
(右连接)
SELECT <select_list>
FROM Table_A A
RIGHT JOIN Table_B B
ON A.Key = B.Key
4.OUTER JOIN
(外连接)
SELECT <select_list>
FROM Table_A A
FULL OUTER JOIN Table_B B
ON A.Key = B.Key
5.LEFT JOIN EXCLUDING INNER JOIN
(左连接-内连接)
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
(右连接-内连接)
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
(外连接-内连接)
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
↓ ↓ ↓ 加入技术交流群 ↓ ↓ ↓
推荐阅读
1. Cookie、Session、Token那点事儿
2. 10 款 GitHub 插件
3. Intellij IDEA调试功能使用总结
4. 微信扫码登录实战(附代码)
本文分享自微信公众号 - Java后端(web_resource)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。