자격증/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;
반응형