MENU

数据库常用Join查询

July 9, 2022 • Read: 293 • mysql学习

1.查询A,B表共有部分内容:

SELECT <select_list>

FROM TableA A INNER JOIN TableB B ON A.Key = B.Key

2.查询A表所有和AB表共有部分:

SELECT <select_list>

FROM TableA A

LEFT JOIN Table B B

ON A.Key = B.Key

3.查询B表所有和AB表共有部分:

SELECT <select_list>

FROM TableA A

RIGHT JOIN TableB B

ON A.Key = B.Key

4.查询A表独有部分内容:

SELECT <select_list>

FROM TableA A

LEFT JOIN TableB B

ON A.Key = TableB B

ON A.Key = B.Key

WHERE B.Key IS NULL

5.查询B表独有部分:

SELECT <select_list>

FROM TableA A
RIGHT JOIN TableB B

ON A.Key = B.Key
WHERE A.Key IS NULL
6.查询AB表所有部分:

SELECT <sclect_list>

FROM TableA A
FULL OUTER JOIN TableB B

ON A.Key = B.Key

7.查询AB表各自独有部分

SELECT<select_list>

FROM TableA A
FULL OUTER JOIN TableB B

ON A.Key = B.Key
WHERE A.Key IS NULL OR B.Key IS NULL

兼总条贯 知至知终

无标签