본문 바로가기
DataBase

SQL 다중 outer join

by ma_ro 2020. 1. 22.

3개의 테이블을 JOIN 하면서 한 테이블의 key 값을 두번 써야 하고, 데이터 row는 변하면 안되는 경우.

JOIN 문은 여러번 써서 해결. 조회 시간은 3배로 늘어남..

SELECT
     t1.airline_id,
     t2.name,
     t1.source_id,
     t3.name AS 'source_airport_name',
     t1.dest_id,
     t4.name AS 'dest_airport_name'
FROM routes t1
LEFT JOIN 
     airlines t2
ON 
     t1.airline_id = t2.id
LEFT JOIN 
     airports t3
ON 
     t1.source_id = t3.id
LEFT JOIN 
     airports t4
ON 
     t1.dest_id = t4.id

 

'DataBase' 카테고리의 다른 글

SQL group by  (0) 2020.01.22
SQL case when  (0) 2020.01.22

댓글