-- 위에 데이터에 한정해서.. WITH T1 AS ( SELECT '1' CD ,'사과' NM FROM DUAL UNION ALL SELECT '2','배' FROM DUAL UNION ALL SELECT '3','포도' FROM DUAL UNION ALL SELECT '4','귤' FROM DUAL ),T2 AS ( SELECT '1' CD ,'사과' NM FROM DUAL UNION ALL SELECT '2','배' FROM DUAL ) SELECT * FROM (SELECT T1.CD , CASE WHEN &VAL = 'TOTAL' THEN T1.NM WHEN &VAL = 'Y' AND T1.CD = T2.CD THEN T1.NM WHEN &VAL = 'N' AND ( T1.CD <> T2.CD OR T2.CD IS NULL ) THEN T1.NM END NM FROM T1 , T2 WHERE T1.CD = T2.CD(+) ) WHERE NM IS NOT NULL