SQL 的各种 join 用法
作者:C.L. Moffatt
http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
7种 join 用法
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
古人学问无遗力,少壮工夫老始成。
纸上得来终觉浅,绝知此事要躬行。