总结 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);

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

上一篇:【MySQL】03-事务隔离


下一篇:解决MySQL8 #1227 – Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this ...