下圖展示了 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
注:本文章僅限于交流使用,如有侵權請聯系删除
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!