下圖展示了 LEFT JOIN气筋、RIGHT JOIN拆内、INNER JOIN、OUTER JOIN 相關(guān)的 7 種用法宠默。
具體分解如下:
1.INNER JOIN(內(nèi)連接)
SELECT<select_list>
FROMTable_A A
INNERJOINTable_B B
ONA.Key= B.Key
2.LEFT JOIN(左連接)
SELECT
FROMTable_A A
LEFTJOINTable_B B
ONA.Key= B.Key
3.RIGHT JOIN(右連接)
SELECT
FROMTable_A A
RIGHTJOINTable_B B
ONA.Key= B.Key
4.OUTER JOIN(外連接)
SELECT
FROMTable_A A
FULLOUTERJOINTable_B B
ONA.Key= B.Key
5.LEFT JOIN EXCLUDING INNER JOIN(左連接-內(nèi)連接)
SELECT<select_list>
FROMTable_A A
LEFTJOINTable_B B
ONA.Key= B.Key
WHERE
B.KeyISNULL
6.RIGHT JOIN EXCLUDING INNER JOIN(右連接-內(nèi)連接)
SELECT
FROMTable_A A
RIGHTJOINTable_B B
ONA.Key= B.Key
WHERE
A.KeyISNULL
7.OUTER JOIN EXCLUDING INNER JOIN(外連接-內(nèi)連接)
SELECT
FROMTable_A A
FULLOUTERJOINTable_B B
ONA.Key= B.Key
WHERE
A.KeyISNULLORB.KeyISNULL
擴展閱讀
來源:https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins