UNION、INTERSECT和EXCEPT用于将多个查询语句的结果集进行组合,从而形成一个最终结果。
query
{ UNION [ ALL ] | INTERSECT | EXCEPT | MINUS }
query
UNION:返回两个查询表达式的集合运算。
UNION ALL:ALL关键字用于保留由UNION生成的任何重复行。
INTERSECT:返回派生自两个查询表达式的行的集合运算。返回结果中将丢弃未同时由两个表达式返回的行。
EXCEPT| MINUS:返回派生自两个查询表达式之一的行的集合运算。返回的结果行必须存在于第一个结果表而不存在于第二个结果表中。MINUS和EXCEPT完全同义。
select * from t1
union
select * from t2
except
select * from t3
order by c1;
select * from t1
union
select * from t2
intersect
select * from t3
order by c1;
(select * from t1
union
select * from t2)
intersect
(select * from t3)
order by c1;
在文档使用中是否遇到以下问题
更多建议
匿名提交