存在的记忆

数据库常用Join查询

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

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »