WITH t AS ( SELECT '홍길동' nm, '사과' cd FROM dual UNION ALL SELECT '홍길동', '오렌지' FROM dual UNION ALL SELECT '홍길동', '배' FROM dual UNION ALL SELECT '김영수', '오렌지' FROM dual UNION ALL SELECT '김영수', '배' FROM dual ) SELECT b.nm , a.cd FROM (SELECT DISTINCT cd FROM t) a LEFT OUTER JOIN t b PARTITION BY (b.nm) ON a.cd = b.cd WHERE b.cd IS NULL ;
WITH name_t AS ( SELECT '홍길동' nm FROM dual UNION ALL SELECT '김영수' FROM dual UNION ALL SELECT '구루비' FROM dual ) , fruit_t AS ( SELECT '사과' cd FROM dual UNION ALL SELECT '오렌지' FROM dual UNION ALL SELECT '배' FROM dual ) , name_fruit_t AS ( SELECT '홍길동' nm, '사과' cd FROM dual UNION ALL SELECT '홍길동', '오렌지' FROM dual UNION ALL SELECT '홍길동', '배' FROM dual UNION ALL SELECT '김영수', '오렌지' FROM dual UNION ALL SELECT '김영수', '배' FROM dual ) SELECT a.nm , b.cd FROM name_t a CROSS JOIN fruit_t b LEFT OUTER JOIN name_fruit_t c ON a.nm = c.nm AND b.cd = c.cd WHERE c.cd IS NULL ;