搜索
写经验 领红包
 > 财经

sql各种joi用法详解(sql中的joi)

导语:一张图看懂 SQL 的各种 join 用法

sql各种join用法详解(sql中的join)

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

具体分解如下:

1.INNER JOIN(内连接)

SELECT <select_list> FROM Table_A AINNER JOIN Table_B BON A.Key = B.Key

2.LEFT JOIN(左连接)

SELECT <select_list>FROM Table_A ALEFT JOIN Table_B BON A.Key = B.Key

3.RIGHT JOIN(右连接)

SELECT <select_list>FROM Table_A ARIGHT JOIN Table_B BON A.Key = B.Key

4.OUTER JOIN(外连接)

SELECT <select_list>FROM Table_A AFULL OUTER JOIN Table_B BON A.Key = B.Key

5.LEFT JOIN EXCLUDING INNER JOIN(左连接-内连接)

SELECT <select_list> FROM Table_A ALEFT JOIN Table_B BON A.Key = B.KeyWHERE B.Key IS NULL

6.RIGHT JOIN EXCLUDING INNER JOIN(右连接-内连接)

SELECT <select_list>FROM Table_A ARIGHT JOIN Table_B BON A.Key = B.KeyWHERE A.Key IS NULL

7.OUTER JOIN EXCLUDING INNER JOIN(外连接-内连接)

SELECT <select_list>FROM Table_A AFULL OUTER JOIN Table_B BON A.Key = B.KeyWHERE A.Key IS NULL OR B.Key IS NULL

如果本文对您有帮助,请您关注小编并转发文章,您的支持是我们最大的动力!

本文内容由小欣整理编辑!