minus 관련 질문하나 드립니다 0 5 1,388

by 김큐트 [SQL Query] [2014.01.22 15:03:17]



select * from A minus select * from B

이걸 minus연산자를 제외하고

select 1번만 써서 같은 결과 내는 방법이 있을까요?
by 홍상표 [2014.01.22 15:27:48]
with A as (
select '1' col1 from dual union all
select '2' col1 from dual union all
select '3' col1 from dual union all
select '4' col1 from dual
), 
B as (
select '3' col1 from dual union all
select '4' col1 from dual union all
select '5' col1 from dual union all
select '6' col1 from dual
)

select col1 from A
where not exists ( select 'x' from B
          where B.col1 = A.col1)
;

by 마농 [2014.01.22 15:29:47]
minus 하면 간단하지만...
조인으로 풀면 복잡합니다. 모든 컬럼을 비교해야 하기 때문입니다.
컬럼의 갯수, 각 컬럼의 데이터 타입, 각 컬럼의 널 저장 여부 등 고려해야 할 것이 많습니다.

by 김큐트 [2014.01.22 15:59:47]
아.... 저런식으로 한번 풀어보려고 했는데 그렇군요 감사합니다

by 홍상표 [2014.01.22 15:30:58]
 
with A as (
select '1' col1 from dual union all
select '2' col1 from dual union all
select '3' col1 from dual union all
select '4' col1 from dual
), 
B as (
select '3' col1 from dual union all
select '4' col1 from dual union all
select '5' col1 from dual union all
select '6' col1 from dual
)
select A.col1 from A, B
where A.col1 = B.col1(+)
and   B.col1 is null

by 김큐트 [2014.01.22 15:58:21]
감사합니다 정말 많은 도움이 됬어요
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입