【Oracle&SQLServer】并集、交际、补集

来源:互联网 发布:单片机hex读取工具 编辑:程序博客网 时间:2024/04/28 16:14

1、并集(UNION/UNION ALL)

Oracle&SQLServer中用法一致

UNION去重UNION ALL不去重

 

复制代码
-- 去重select * from tableaunionselect * from tableb-- 不去重select * from tableaunion allselect * from tableb
复制代码

 

 2、交集(INTERSECT/EXISTS)

Oracle&SQLServer中用法一致

INTERSECT去重EXISTS不去重

 

复制代码
-- 去重select * from tableaintersectselect * from tableb-- 不去重select * from tablea awhere exists (select 1 from tableb b where a.ID=b.ID)
复制代码

 

3、补集(MINUS/EXCEPT/NOT EXISTS)

Oracle:

MINUS去重NOT EXISTS不去重

 

 

SQLServer:

EXCEPT去重NOT EXISTS不去重

 

 

复制代码
-- Oracle去重select * from tableaminusselect * from tableb-- SQLServer去重select * from tableaexceptselect * from tableb-- Oracle&SQLServer不去重select * from tablea awhere not exists (select 1 from tableb b where a.ID=b.ID)
0 0
原创粉丝点击