交集、并集和补集
更新时间:2019-10-09 16:52:19
本文为您介绍UNION、UNOIN ALL、UNION DISTINCT并集,INTERSECT、INTERSECT ALL、INTERSECT DISTINCT交集,EXCEPT、EXCEPT ALL、EXCEPT DISTINCT补集等SQL语法。
语法格式如下。
select_statement UNION ALL select_statement;
select_statement UNION [DISTINCT] select_statement;
select_statement INTERSECT ALL select_statement;
select_statement INTERSECT [DISTINCT] select_statement;
select_statement EXCEPT ALL select_statement;
select_statement EXCEPT [DISTINCT] select_statement;
select_statement MINUS ALL select_statement;
select_statement MINUS [DISTINCT] select_statement;
UNION
: 求两个数据集的并集,即将两个数据集合并成一个数据集。INTERSECT
:求两个数据集的交集,即输出两个数据集均包含的记录。EXCEPT
: 求第二个数据集在第一个数据集中的补集,即输出第一个数据集包含而第二个数据集不包含的记录。MINUS(Oracle)
: 等同于EXCEPT
。
带all的不取重,不带all默认取重, minus没用all用法