假設有表tableA、tableB,他們都有字段id和name
交集:INTERSECT (適用於兩個結果集)
select a.id, a.name from tableA a INTERSECT select b.id, b.name from tableB b
差集:MINUS(適用於兩個結果集)
select a.id, a.name from tableA a MINUS select b.id, b.name from tableB b
並集:UNION(適用於兩個結果集)
-- UNION、UNION ALL能對兩個或以上的結果集進行合並 -- 不包括重復行,進行默認排序 select a.id, a.name from tableA a UNION select b.id, b.name from tableB b -- 包括重復行,不進行默認排序 select a.id, a.name from tableA a UNION ALL select b.id, b.name from tableB b