개발노트

FULL OUTER JOIN 본문

자격증/SQLD

FULL OUTER JOIN

dev? 2024. 11. 14. 14:52
반응형

2개의 테이블이 존재 

CREATE VIEW V_EMPLOYEES AS (
    SELECT 1 AS EMP_ID, 'ALICE' AS NAME, 100 AS SALARY FROM DUAL UNION ALL
    SELECT 2 AS EMP_ID, 'BOB' AS NAME, 200 AS SALARY FROM DUAL UNION ALL
    SELECT 3 AS EMP_ID, 'CHARLIE' AS NAME, 300 AS SALARY FROM DUAL);

CREATE VIEW V_PROJECT AS (
    SELECT 1 AS PROJ_ID, 'PROJECT A' AS PRJO_NAME, 1 AS EMP_ID FROM DUAL UNION ALL
    SELECT 2 AS PROJ_ID, 'PROJECT B' AS PRJO_NAME, 2 AS EMP_ID FROM DUAL UNION ALL
    SELECT 3 AS PROJ_ID, 'PROJECT C' AS PRJO_NAME, 4 AS EMP_ID FROM DUAL);

 

FULL OUTER JOIN 결과

SELECT
    E.EMP_ID, E.NAME, E.SALARY,
    P.PROJ_ID, P.PRJO_NAME
FROM V_EMPLOYEES E
FULL OUTER JOIN V_PROJECT P
ON E.EMP_ID = P.EMP_ID
ORDER BY 1,4;

 

반응형

'자격증 > SQLD' 카테고리의 다른 글

(다중행 서브쿼리) ALL / ANY  (0) 2024.11.14
서브쿼리 (단일 / 다중 행)  (0) 2024.11.14
USING절, NATURAL JOIN 쿼리 결과 특징  (0) 2024.11.12
NATURAL JOIN  (0) 2024.11.12
ON을 USING으로 바꾸기  (0) 2024.11.12