두개의 테이블에서 다른 데이터 row 추출 0 2 1,731

by 쿼리back [SQL Query] [2015.10.16 09:31:00]


안녕하세요, 먼저 제글에 읽어주신 분들께 감사의 말씀드립니다.

아래와 같이 두개의 테이블에서 다른 데이터만 뽑는 쿼리를 짰는데요.

좀 깔끔하게 튜닝이 가능할지 질문드립니다....(--)(_ _)꾸벅~

 with t(id , col1 , col2) as

 (select 1111 , 10 ,   'a'
 from dual union all
 select 2222 , 10 ,   'c'
 from dual
 union all
 select 3333 , 30 ,   'b'
 from dual
 )
 ,t1(id , col1 , col2) as
 (select 1111 , 11 ,   'b'
 from dual union all
 select 2222 , 10 ,   'a'
 from dual
 union all
 select 3333 , 30 ,   'b'
 from dual
 )
 select *
 from (
 select t.id, decode(t.col1,t1.col1,'C','t.col1:'||t.col1||', t1.col1:'||t1.col1) col1 
       ,decode(t.col2,t1.col2,'C','t.col2:'||t.col2||', t1.col2:'||t1.col2) col2
 from t , t1
 where t.id = t1.id
 )
 where  col1 != 'C'
     or col2 != 'C'

by 창조의날개 [2015.10.16 09:39:25]

 select t.id, decode(t.col1,t1.col1,'C','t.col1:'||t.col1||', t1.col1:'||t1.col1) col1 
       ,decode(t.col2,t1.col2,'C','t.col2:'||t.col2||', t1.col2:'||t1.col2) col2
 from t , t1
 where t.id = t1.id
   AND (T.COL1 != T1.COL1 OR T.COL2 != T1.COL2)
 ;

 


by 우리집아찌 [2015.10.16 09:49:33]

깔끔하진 않지만 minus 쓰는방법도 있지요

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입