Join的7种用法
- 左连接
即使右表中没有匹配,也从左表返回所有行。
Select [选项] from tableA A left [outer] join tableB B on A.key=B.key;
- 左连接带where条件
Select [选项] from tableA A left [outer] join tableB B on A.key=B.key where B.key is null;
- 右连接
即使左表中没有匹配,也从右表返回所有的行。
Select [选项] from tableA A right [outer] join tableB B on A.key=B.key;
- 右连接带where条件
Select [选项] from tableA A right [outer] join tableB B on A.key=B.key where A.key is null;
- 全连接
只要其中一个表中存在匹配,则返回行。
Select [选项] from tableA A full outer join tableB B on A.key=B.key;
- 全外连接带where条件
Select [选项] from tableA A full outer join tableB B on A.key=B.key where A.key is null or B.key is null;
- 内连接
如果表中有至少一个匹配,则返回行。
Select [选项] from tableA A [inner] join tableB B on A.key=B.key;inner写不写都是内链接。