谈谈oracle里的join、left join、right join、full join-版本2

栏目: mysql · 发布时间: 2020-08-31

来源: ORACLE-fans

作者:ORACLE-fans

简介  这篇文章主要介绍了谈谈oracle里的join、left join、right join、full join-版本2以及相关的经验技巧,文章约2698字,浏览量292,点赞数6,值得推荐!


--1.left join  左表为主表,左表返回全部数据,右表只返回与左表相匹配的数据
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fpdm,t2.fphm,t2.zflx  from yw_zjfpjl t1
left join xxdzmx t2  on t2.fpdm||t2.fphm=t1.fpdm||t1.fphm

select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fpdm,t2.fphm,t2.zflx  from yw_zjfpjl t1 , xxdzmx t2  where t2.fphm=t1.fphm(+)

--2.right join 右表为主表,右表返回全部数据,左表只返回与右表相匹配的数据
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fpdm,t2.fphm,t2.zflx  from yw_zjfpjl t1
right join xxdzmx t2  on t2.fpdm||t2.fphm=t1.fpdm||t1.fphm

--3.inner join  只返回两表相匹配的数据
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid, t2.fphm,t2.fpdm,t2.zflx  from yw_zjfpjl t1
inner join xxdzmx t2  on t2.fphm||t2.fpDm = t1.fphm||t1.fpdm
where t2.fphm is not null and t2.zflx=‘0‘ and t1.zflx=‘0‘ and TO_CHAR(t1.zjsj,‘YYYY-MM‘)=‘2016-10‘  and substr(t2.dzyf, 0, 4)||‘-‘||substr(t2.dzyf, 5, 2)=‘2016-10‘;

--4.full join
--4.1全部结果集  106
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fpdm,t2.fphm,t2.zflx  from yw_zjfpjl t1
full join xxdzmx t2  on t2.fpdm=t1.fpdm and t2.fphm=t1.fphm

--4.2右边有左边没有   10-1=9
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fphm,t2.fpdm,t2.zflx,t2.dzyf  from yw_zjfpjl t1
full join xxdzmx t2  on t2.fphm||t2.fpDm = t1.fphm||t1.fpdm
where t2.fphm is not  null and t2.zflx =0 and substr(t2.dzyf,1 ,4)||‘-‘||substr(t2.dzyf,5,2)=‘2016-10‘  

--4.3左边有右边没有   97-1=96
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fphm,t2.fpdm,t2.zflx  from yw_zjfpjl t1
full join xxdzmx t2  on t2.fphm||t2.fpDm = t1.fphm||t1.fpdm
where  (t1.zflx=‘0‘ and TO_CHAR(t1.zjsj,‘YYYY-MM‘)=‘2016-10‘  );

--4.4左边有右边没有  右边有左边没有  (97-1)+(10-1)=105
select   t1.fpdm,t1.fphm ,t1.zjr,t1.zjsj,t1.zjjx,t1.zjje,t1.zflx,t1.zfid,t2.fphm,t2.fpdm,t2.zflx,t2.dzyf  from yw_zjfpjl t1
full join xxdzmx t2  on t2.fphm||t2.fpDm = t1.fphm||t1.fpdm
where (t2.fphm is not  null and t2.zflx =‘0‘ and substr(t2.dzyf,1 ,4)||‘-‘||substr(t2.dzyf,5,2)=‘2016-10‘) or (t1.zflx=‘0‘ and TO_CHAR(t1.zjsj,‘YYYY-MM‘)=‘2016-10‘  );








































以上就是本文的全部内容,希望对大家的学习有所帮助,本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 原文地址:http://www.cnblogs.com/iyoume2008/p/6407711.html

Oracle的left join中on和where的区别

Oracle中 (+)与left join 的用法区别

oracle 视图的创建,游标,left join

oracle left join 注意事项(示例代码)

oracle SQL left join()或full out join()根据键排除记录(示例代码)

Oracle表与表之间的连接方式(内连接:inner join 、外连接 全连接: full outer join、左连接:left outer join 、右连接:right outer join

MySQL、SQLServer、Oracle的update left join语法

深入Oracle的left join中on和where的区别详解