目录
干货
1、select * from tableA A left join tableB B on A.key=B.key;
A、B的共有加上A的独有
2、select * from tableA A right join tableB B on A.key=B.key;
A、B的共有加上B的独有
3、select * from tableA A left join tableB B on A.key=B.key where B.key is null;
A的独有
4、select * from tableA A inner join tableB B on A.key=B.key;
A、B的共有
5、select * from tableA A right join tableB B on A.key=B.key where A.key is null;
B的独有
6、select * from tableA A left join tableB B on A.key=B.key
union(合并和去重)
select * from tableA A right join tableB B on A.key=B.key
AB两个全有
7、select * from tableA A left join tableB B on A.key=B.key where B.key is null
union
select * from tableA A right join tableB B on A.key=B.key where B.key is null
A的独有+B的独有
下面是连接查询的详细内容
为了便于理解SQL语句,给出所有实例用到的三张表的数据如下:
good表记录
type表记录
leavel表记录