oracle中的连接问题

这个连接问题我学习了好几次,每次都有新的领悟,但是经常会忘记,这次做一个全面的记录,只写写语法,实例就不写了


内连接:

 内连接分为等值连接,不等值连接,自然连接

 等值连接:所有条件相等的列合在一起

select a.*,b.* from a inner join b on a.id=b.id;
select a.*,b.* from a,b where a.id=b.id;
不等值连接:就是后面的条件判断不是等号
select a.*,b.* from a inner join b on a.id>b.id;
select a.*,b.* from a,b where a.id>b.id;
自然连接:就是加强版的等值连接,不会显示重复列,如果你的列名一个一个的写也就不存这个问题了
select a.*,b.* from a natural join b on a.id=b.id;


 
 

外连接:

外连接分外左外连接,右外连接,全外连接(outer可有可无)

右外连接:右边表全部显示,左边表没有的为null(两种写法我都写上)

select a.*,b.* from a right outer join b on a.id=b.id;select a.*,b.* from a,b where a.id(+)=b.id;

左外连接:左边表全部显示,右边表没有的为null(两种写法我都写上)

select a.*,b.* from a left outer join b on a.id=b.id;select a.*,b.* from a,b where a.id=b.id(+);

全外连接:所有的行都显示,谁没有谁为空

select a.*,b.* from a full join b on a.id=b.id;

 
 
 
 

交叉连接:

 交叉连接就是笛卡尔积也就是所有可能的数据组合

不带where:

select a.*,b.* from a cross join b 带where:select a.*,b.* from a cross join b on a.id=b.id

写的有点简单,主要是这个概念理解和写法理解了再复杂的也不担心了

 
 

猜你喜欢

转载自blog.csdn.net/zhutiandashen/article/details/56676888