본문 바로가기

[2016 - 2019] 학부 정리/DataBase

[DB공부] 8. 집합연산 - 미완성

집합 연산자


- 합집합 (union / union all)

   union : 중복행 제거

   union all : 중복행 포함

select employee_id, job_id

from employees

union

select employee_id, job_id

from job_history;


- 교집합 (intersect)

- 차집합 (minus)


- 공통열이 존재하지 않을 경우

select employee_id, job_id,salary 

from employees 

union 

select employee_id, job_id, 0 

from   job_history;


select country_id, country_name

from countries

minus

select l.country_id, c.country_name

from locations l

join countries c

on l.country_id = c.country_id

join departments d

on d.location_id = l.location_id;