作者:C.L. Moffatt
來自:http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
下圖展示了 LEFT JOIN、RIGHT JOIN、INNER JOIN、OUTER JOIN 相關的 7 種用法。
具體分解如下:
1、INNER JOIN(內連線)
SELECT
FROM Table_A A
INNER JOIN Table_B B
ON A.Key = B.Key
2、LEFT JOIN(左連線)
SELECT
FROM Table_A A
LEFT JOIN Table_B B
ON A.Key = B.Key
3、RIGHT JOIN(右連線)
SELECT
FROM Table_A A
RIGHT JOIN Table_B B
ON A.Key = B.Key
4、OUTER JOIN(外連線)
SELECT
FROM Table_A A
FULL OUTER JOIN Table_B B
ON A.Key = B.Key
5、LEFT JOIN EXCLUDING INNER JOIN(左連線-內連線)
SELECT
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
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
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
●編號529,輸入編號直達本文
●輸入m獲取文章目錄
Web開發
更多推薦《25個技術類公眾微信》
涵蓋:程式人生、演演算法與資料結構、駭客技術與網路安全、大資料技術、前端開發、Java、Python、Web開發、安卓開發、iOS開發、C/C++、.NET、Linux、資料庫、運維等。