DataBase

left outer join ?

Hyo Kim 2020. 10. 30. 18:00
728x90
반응형

첫 번째 테이블은 조건과 관계없이 모두 결합된다.

 

SELECT [열 목록]

FROM [첫 번째 테이블]

LEFT OUTER JOIN [두 번째 테이블]

ON [조인될 조건]

WHERE [검색 조건]

 

예시)

select a.* , b.device_id
from simple_check_list a
left outer join (select * from simple_device_check where device_id =
#{deviceId}) b
on b.check_list_id = a.check_list_id
where
a.device_type_id = #{deviceTypeId}

 

------------------------------------------------------

select a.* , b.device_id

--> a테이블의 모든열과, b의 device_id 열 사용0
from simple_check_list a

--> 첫 번째 테이블을 a로 지정
left outer join

(select * from simple_device_check where device_id = #{deviceId}) b

--> 두 번째 테이블을 b로 지정 및 device_id가 파라미터값과 같은 것만 조회
on b.check_list_id = a.check_list_id

--> b의 check_list_id와 a의 check_list_id 가 같은 것만 합침
where a.device_type_id = #{deviceTypeId}

-->위 값 중 a의 타입아이디가 파라미터값과 같은 것만 검색

 

check_list_id 

 

 

728x90
반응형