DBA

left join 할때, on 절의 조건과 where절의 조건과의 차이 본문

[2] Database/MS-SQL

left join 할때, on 절의 조건과 where절의 조건과의 차이

코볼 2023. 9. 7. 10:11
728x90
반응형
SMALL

left join 할때, on 절의 조건과 where절의 조건과의 차이

회사에서 일하다가 헷갈려서...

 

---- 1. Left Join을 수행하고 null인 것을 날려 버림. (Row 수가 줄어듬.)
select * from T_AnswerRaw as ar
left join T_Question as q on q.questionNumber = ar.questionNumber and q.subQuestionNumber = ar.subQuestionNumber and q.questionVariable = ar.questionVariable
where ar.answers is not null

---- 2. not null인것에만 Left Join을 수행 함. (T_AnswerRaw의 전체 Row수를 기준으로 나옴.)
select * from T_AnswerRaw as ar
left join T_Question as q on q.questionNumber = ar.questionNumber and q.subQuestionNumber = ar.subQuestionNumber and q.questionVariable = ar.questionVariable
and ar.answers is not null

728x90
반응형
LIST
Comments