oracle合并查询

oracle合并查询:可以获取多个select语句查询结果集,可供选择集合符:union,union all,intersect,minus.

1、union:可以获取两个或多个查询结果集的合集的并集,会自动去掉结果集中的重复行,返回以第一列的结 果进行排序。

eg:

select a.empiId from ehr_healthrecord a , mpi_demographicinfo b where a.empiId = b.empiId
and a.status = '0' and a.deadflag = '2' and a.createunit like '440606003%'
and a.createDate >= to_date('2014/08/16','yyyy/MM/dd')
and a.createDate <= to_date('2014/09/16','yyyy/MM/dd')

union
select a.empiId from ehr_healthrecord a , mpi_demographicinfo b where a.empiId = b.empiId
and a.createunit like '440606003%' and a.updateDate is not null
and a.updateDate >= to_date('2014/08/16','yyyy/MM/dd')
and a.updateDate <= to_date('2014/09/16','yyyy/MM/dd')

2、union all:用于获取两个或多个结果集的并集,不取消重复行,不按照任何列排序。

3、intersect:用于获取两个结果集的交集。只会返回同时存在两个或多个结果集中的数据,以第一列进行排序。

4、minus:用于获取两个结果集的差集。只会显示在第一个结果集中存在,而在其它结果集中不存在的数据。以第一列进行排序。

扫描二维码关注公众号,回复: 1182980 查看本文章

猜你喜欢

转载自710542316.iteye.com/blog/2116880