-
左满外连接
结果集是左表
SELECT <select_list>
FROM tableA A
LEFT JOIN tableB B
ON A.key = B.key;
-
左空外连接
结果是左表去重与右表的交集
SELECT <select_list>
FROM tableA A
LEFT JOIN tableB B
ON A.key = B.key
WHERE B.key IS NULL;
-
右满外连接
结果集是右表
SELECT <select_list>
FROM tableA A
RIGHT JOIN tableB B
ON A.key = B.key
-
右空外连接
结果是右表去重与左表的交集
SELECT <select_list>
FROM tableA A
RIGHT JOIN tableB B
ON A.key = B.key
WHERE A.key IS NULL;
-
内实连接
左表与右表的交集
SELECT <select_list>
FROM tableA A
INNER JOIN tableB B
ON A.key = B.key;
-
内空连接
左表与右表的满集去除两表的交集 (2+4)
SELECT <select_list>
FROM tableA A
LEFT JOIN tableB B
ON A.key = B.key
WHERE B.key IS NULL
UNION ALL
SELECT <select_list>
FROM tableA A
RIGHT JOIN tableB B
ON A.key = B.key
WHERE A.key IS NULL;
-
满外连接
左表与右表的满集 (1+4 或 2+3)
SELECT <select_list>
FROM tableA A
LEFT JOIN tableB B
ON A.key = B.key
UNION ALL
SELECT <select_list>
FROM tableA A
RIGHT JOIN tableB B
ON A.key = B.key
WHERE A.key IS NULL;