首页 > 数据库技术 > 详细

PostgreSQL(EXCEPT,INTERSECT)

时间:2015-11-06 17:58:18      阅读:297      评论:0      收藏:0      [点我收藏+]

except 可以查看表一对表二不一样的数据,有点像是对表一进行表一表二交集的反集的交集,好绕;

intersect 可以查看表一和表二一样的数据,求交集;

 

select t1.name,t1.age,t1.country from table_1 t1

except

select t2.name,t2.age,t2.country from table_2 t2 order by name,age;

可以对两表使用where条件;

 

可以将except结果创建成一张新的表:

create table table_3 as (

select t1.name,t1.age,t1.country from table_1 t1

except

select t2.name,t2.age,t2.country from table_2 t2 order by name,age;

);

 

可以将except结果插入另一张表:

insert into table_2(name,age,country)

select t1.name,t1.age,t1.country from table_1 t1

except

select t2.name,t2.age,t2.country from table_2 t2 order by name,age;

PostgreSQL(EXCEPT,INTERSECT)

原文:http://www.cnblogs.com/apro-abra/p/4943130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!