For multiple select statements merged results
- union and set deduplication
- and not re-set union all
- intersect intersection
- minus difference set
union
The combined set A and set B, but a set of two repeated portion is removed, are sorted
select deptno,ename from emp where deptno in (20,30) union select deptno,ename from emp where deptno in (20,10); DEPTNO ENAME ---------- ---------- 10 CLARK 10 KING 10 MILLER 20 ADAMS 20 FORD 20 JONES 20 SCOTT 20 SMITH 30 ALLEN 30 BLAKE 30 JAMES 30 MARTIN 30 TURNER 30 WARD
union all
The combined set A and set B, not heavy, not ordering
select deptno,ename from emp where deptno in (20,30) union all select deptno,ename from emp where deptno in (20,10); DEPTNO ENAME ---------- ---------- 20 SMITH 30 ALLEN 30 WARD 20 JONES 30 MARTIN 30 BLAKE 20 SCOTT 30 TURNER 20 ADAMS 30 JAMES 20 FORD 20 SMITH 20 JONES 10 CLARK 20 SCOTT 10 KING 20 ADAMS 20 FORD 10 MILLER 19 rows selected.
intersect
The intersection of two sets of portions, and to re-sort
select deptno,ename from emp where deptno in (20,30) intersect select deptno,ename from emp where deptno in (20,10); DEPTNO ENAME ---------- ---------- 20 ADAMS 20 FORD 20 JONES 20 SCOTT 20 SMITH
minus
Taking the difference of the set of the two sets, the set A is present, it does not exist in the set of data B (B taken in the aggregate data set A does not exist), deduplication
select deptno,ename from emp where deptno in (20,30) minus select deptno,ename from emp where deptno in (20,10); DEPTNO ENAME ---------- ---------- 30 ALLEN 30 BLAKE 30 JAMES 30 MARTIN 30 TURNER 30 WARD 6 rows selected.