取得AB两表的交集,A表减交集,B表减交集,这三个SQL的语法。

来源:互联网 发布:unity3d 动画 编辑:程序博客网 时间:2024/06/06 02:54
 

假设id是主键

AB两表的交集
select   a.*   from   A   a   where   exists   (select   1   from   B   b   where   b.id=a.id)

A表减交集
select   a.*   from   A   a   where   not   exists   (select   1   from   B   b   where   b.id=a.id)

B表减交集
select   b.*   from   B   b   where   not   exists   (select   1   from   A   a   where   b.id=a.id)