WITH A AS ( SELECT 'A' AS A FROM DUAL UNION ALL SELECT 'B' AS A FROM DUAL UNION ALL SELECT 'C' AS A FROM DUAL ), B AS ( SELECT 'A' AS A, '1' AS B FROM DUAL UNION ALL SELECT 'A' AS A, '2' AS B FROM DUAL UNION ALL SELECT 'B' AS A, '1' AS B FROM DUAL UNION ALL SELECT 'C' AS A, '3' AS B FROM DUAL UNION ALL SELECT 'C' AS A, '4' AS B FROM DUAL ) SELECT A.A, B.B FROM A LEFT JOIN B ON A.A = B.A AND B.B = '1'
해당 쿼리 수행결과가 저는
A | B |
A | 1 |
A | NULL |
B | 1 |
C | NULL |
C | NULL |
로 예상을 했는데
A | B |
A | 1 |
B | 1 |
C | NULL |
이렇게 결과가 나오는데 왜 이렇게 나오는지 모르겠습니다.
OUTER JOIN 은 ON절에 조건 직접 주면 조건에 안맞을시 NULL로 나오는거 아닌가요??
WITH A AS ( SELECT 'A' AS A FROM DUAL UNION ALL SELECT 'B' AS A FROM DUAL UNION ALL SELECT 'C' AS A FROM DUAL ), B AS ( SELECT 'A' AS A, '1' AS B FROM DUAL UNION ALL SELECT 'A' AS A, '2' AS B FROM DUAL UNION ALL SELECT 'B' AS A, '1' AS B FROM DUAL UNION ALL SELECT 'C' AS A, '3' AS B FROM DUAL UNION ALL SELECT 'C' AS A, '4' AS B FROM DUAL ) SELECT A.A , CASE WHEN B.B = '1' THEN '1' END FROM A LEFT JOIN B ON A.A = B.A