一、内外连接全连接,左右连接
隐式 内连接 select * from a,b where a.列名 = b.列名
select * from a left
outer join b on a.id = b.id
select * from a right outer join b on a.id = b.id
可以使用union来达到全外连接的查询效果。
union :可以将左外连接查询和右外连接查询两条sql语句使用union合并起来进行查询,去掉重复的数据。
内连接:
1、 隐式内连接:
Select * from a,b where a.id = b.id;
结果:C
2、 显示内连接:
Select * from a inner join b on a.id = b.id;
结果:C
外连接:
1、 左外连接
select * from a left outer join b on a.id = b.id
结果:A+C
2、 右外连接
select * from a right outer join b on a.id = b.id
结果:B+C
3、 union:相当于全外连接
select * from a left outer join b on a.id = b.id
union
select * from a right outer join b on a.id = b.id
结果:A+B+C,会自动虑重
select * from a left outer join b on a.id = b.id
union all
select * from a right outer join b on a.id = b.id
结果:A+B+C,有重复数据
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">