Inner Join of Multiple Relations (여러 테이블 조인)

coding_bird·2022년 4월 16일
0
  • 작성자는 oracle을 기준으로 공부하고 있습니다

여기서는 3개의 table을 inner join하는 문법에 대해 설명한다.

아래는 employees, departments, locations 테이블을 서로 inner join하는 과정이다.
이때 employees 와 departments는 department_id라는 공통 열을 가지고,
departments와 locations는 location_id라는 공통 열을 가진다.

틀린 작성문

select e.last_name, d.department_name, l.location_id, l.city
from employees e inner join departments d inner join locations l
on (e.department_id = d.department_id and d.location_id = l.location_id)

위의 구문은 언뜻 보기에는 맞아 보이지만 (적어도 나에게는), 틀린 문법에 해당한다.

아래는 2가지의 옳은 작성문이다

inner join 구문을 사용한 경우

select e.last_name, d.department_name, l.location_id, l.city
from employees e
inner join departments d on e.department_id = d.department_id
inner join locations l on d.location_id = l.location_id

where 구문을 사용한 경우

select e.last_name, d.department_name, l.location_id, l.city
from employees e, departments d, locations l
where e.department_id = d.department_id
and d.location_id = l.location_id

referenced

profile
소프트웨어 세상 날아다니는 중입니다

0개의 댓글