728x90
UNION , UNION ALL 차이점 및 사용방법

 

둘 다 SELECT 조회의 결과문을 하나로 합치는 연산자 (합집합 같은 것)

UNION 은 중복을 제거하고 UNION ALL 은 중복을 포함하여 반환한다.

 

기본규칙
select employee_id, job_id
from employees
union
select employee_id, job_id
from job_history;

 

1) 열의 개수와 순서가 동일해야함

2) 데이터 형식이 동일해야함

 

INSERSECT

양쪽 모두의 교집합만 반환

 

select employee_id, job_id
from employees
intersect
select employee_id, job_id
from job_history;

 

* 그림으로 이해

728x90

+ Recent posts