여기서는 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가지의 옳은 작성문이다
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
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