본문 바로가기
Programming/DataBase

[mssql] left outer join

by 막이 2012. 12. 13.

SELECT c.job_nm,
m1.major_desc major_desc_1,
m2.major_desc major_desc_2,
m3.major_desc major_desc_3,
m4.major_desc major_desc_4,
m5.major_desc major_desc_5
FROM
job_education e ,
job_class c

LEFT OUTER JOIN JOB_MAJOR m1 ON e.edu_cd1 = m1.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m2 ON e.edu_cd2 = m2.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m3 ON e.edu_cd3 = m3.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m4 ON e.edu_cd4 = m4.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m5 ON e.edu_cd5 = m5.MAJOR_CD
WHERE
c.JOB_CD = e.JOB_CD
AND
c.JOB_DEPTH =3

==> 위의 쿼리를 실행하면

"여러 부분으로 구성된 식별자 " e.edu_cd1"은 바인딩할수 없습니다. serverity 16 " 에러가 발생된다.

해결방법.

아래와 같이 from 절의 테이블 순서를 변경해주면된다.

FROM
job_education e
LEFT OUTER JOIN JOB_MAJOR m1 ON e.edu_cd1 = m1.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m2 ON e.edu_cd2 = m2.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m3 ON e.edu_cd3 = m3.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m4 ON e.edu_cd4 = m4.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m5 ON e.edu_cd5 = m5.MAJOR_CD
,job_class c

혹은

FROM
job_class c,
job_education e
LEFT OUTER JOIN JOB_MAJOR m1 ON e.edu_cd1 = m1.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m2 ON e.edu_cd2 = m2.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m3 ON e.edu_cd3 = m3.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m4 ON e.edu_cd4 = m4.MAJOR_CD
LEFT OUTER JOIN JOB_MAJOR m5 ON e.edu_cd5 = m5.MAJOR_CD

이렇게 순서를 바꾸어주면 job_class 컬럼명을 select 어느 위치에 와도 문제가 없다.