inner join
left outer join
right outer join
full outer join
四者的区别
答
cross join 是笛卡儿乘积 就是一张表的行数乘以另一张表的行数
a left join b:返回a的全部行--》b中满足的行以及b中没有满足的行(用null代替)
a right join b:同上不过是ab调换一下
full join 返回两张表中的行 left join+right join
inner join 只返回两张表连接列的匹配项
a表
1,'x'
2,'y'
3,'z'
b表
1,'a'
4,'b'
5,'c'
inner join 内连接:
select a.id ,a.name,b.id,b.name from a,b
where a.id = b.id
1,'x',1,'a'
left outer join 左连接
select a.id ,a.name,b.id,b.name from a
left outer join b on a.id =b.id
1,'x',1,'a'
2,'y',null,null
3,'z',null,null
right outer join 右连接
select a.id ,a.name,b.id,b.name from a
right outer join b on a.id =b.id
1,'x',1,'a'
null,null,4,'b'
null,null,5,'c'
full outer join 外连接
select a.id ,a.name,b.id,b.name from a
full outer join b on a.id =b.id
1,'x',1,'a'
2,'y',null,null
3,'z',null,null
null,null,4,'b'
null,null,5,'c'
阅读(2313) | 评论(0) | 转发(0) |