Set

  • 두 select문을 통해 얻어온 결과에 대해 집합 연산을 할 수 있는 명령문이다.
  • 두 select문을 통해 가져온 컬럼의 형태가 완전히 일치해야 한다.
  • UNION : 합집합
  • UNIONALL : 합집합, 중복된 데이터를 모두 가져온다.
  • INTERSECT : 교집합
  • MINUS : 차집합

ex)

-- UNION : 합집합(중복없음)
select empno, ename, job, deptno
from emp
where deptno = 10
union
select empno, ename, job, deptno
from emp
where job = 'CLERK';

ex)

-- UNION ALL : 합집합(중복있음)
select empno, ename, job, deptno
from emp
where deptno = 10
union all
select empno, ename, job, deptno
from emp
where job = 'CLERK';

ex)

-- INTERSECT : 교집합
select empno, ename, job, deptno
from emp
where deptno = 10
intersect
select empno, ename, job, deptno
from emp
where job = 'CLERK';

ex)

-- MINUS : 차집합
select empno, ename, job, deptno
from emp
where deptno = 10
minus
select empno, ename, job, deptno
from emp
where job = 'CLERK';

Comment and share

  • page 1 of 1

Hyeon Soo Ahn

author.bio


author.job