select * from tableA a inner join tableB b on a.id=b.id;
- 左连接
left join
- 得到的是以左表为主的包括右表一些相同部分的结果
select * from tableA a left join tableB b on a.id=b.id;
- 右连接
right join
- 得到的是以右表为主的包括左表一些相同部分的结果
select * from tableA a right join tableB b on a.id=b.id;
select * from tableA a left join tableB b on a.id=b.id where b.id is null;
select * from tableA a right join tableB b on a.id=b.id where a.id is null;
select * from tableA
union
select * from tableB
select * from tableA a right join tableB b on a.id=b.id where a.id is null
union
select * from tableA a left join tableB b on a.id=b.id where b.id is null;