总结 sql 的 并集、交集、差集

有两个表 ,表a ,表b ,

create table a { age  int , name varchar(20) } ending=innodb;

insert into a values(13,cen);

insert into a values(18,yue);

 

create table b { age  int , name varchar(20) } ending=innodb;

insert into b values(13,cen);

insert into b values(16,tom);

 

1.并集

select * from a union select * from b;

2.交集

select * from a  a1 where exists (select * from b b1 where a1.age = b1.age and a1.name = b1.name);

3.差集

select * from a a1 where not exists(select * from b1 where a1.age = b1.age and a1.name = b1.name);

posted @ 2020-06-19 22:37  岑惜  阅读(1390)  评论(0编辑  收藏  举报