데이터별로 다른 조건의 데이터를 구하고 싶습니다. 고수님들의 코치 부탁드려요 ㅠ.ㅠ
table1.
서울 8011 8012 8013 경기 8012 8013 8014
table2.
서울 8011 8012 경기 8012
위 두개의 table 중 table1 의 데이터 중 table2 에 없는 데이터만 구하고 싶습니다. 같은 지역에서만 비교해야 하고요~
result. 서울 8013 경기 8013 8014
부탁드려요~~~~
오라클 집합 연산자중에 차집합 minus를 사용하시면 됩니다.
select * from table1
minus
select * from table2
with t1 as ( select '서울' city, '8011' code from dual union all select '서울' , '8012' from dual union all select '서울' , '8013' from dual union all select '경기' , '8012' from dual union all select '경기' , '8013' from dual union all select '경기' , '8014' from dual ), t2 as ( select '서울' city, '8011' code from dual union all select '서울' , '8012' from dual union all select '경기' , '8012' from dual ) select a.* from t1 a where not exists ( select '' from t2 b where a.city = b.city and a.code = b.code )
SELECT t1.* FROM t1, t2 WHERE t1.city = t2.city(+) AND t1.code = t2.code(+) AND t2.city IS NULL ;
SELECT * FROM t1 WHERE (city, code) NOT IN (SELECT city, code FROM t2) ;
댓글 주신 모든 분들 감사합니다~ 덕분에 잘 해결 되었어요!!!