关于数据库:MySQL-中内连接外连接等的区别

39次阅读

共计 780 个字符,预计需要花费 2 分钟才能阅读完成。

要想面对一个新的开始,一个人必须有幻想、有心愿、有对将来的神往。如果没有这些,就不叫新的开始,而叫流亡。

下图展现了 LEFT JOIN、RIGHT JOIN、INNER JOIN、OUTER JOIN 相干的 7 种用法。

具体合成如下:

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

正文完
 0