database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
ㆍDB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DB2 Q&A 1058 게시물 읽기
No. 1058
NOT EXISTS
작성자
exists
작성일
2006-07-25 17:20ⓒ
2006-07-25 17:27ⓜ
조회수
7,935

아래는 실제 사용하는 쿼리와 거의 틀린게 없는 쿼리 입니다.

SELECT A, B, C, D, E

FROM TABLE1

WHERE NOT EXISTS (

SELECT 1

FROM TABLE1, TABLE2

WHERE

TABLE1.A=TABLE2.A

AND TABLE1.B = TABLE2.B

)

 

이렇게 하면 TABLE1 내용중 TABLE2 에 있는 내용은 안나온다고 여기서 찾았습니다.

NOT EXISTS 가 안먹힙니다.

 

TABLE2 는 TABLE1 의 mirror 테이블 입니다.

 

TABLE1 의 내용중 TABLE2 에 없는 것만 SELECT 하려 합니다.

 

위 서브 쿼리 내용중 "SELECT 1" <- 이게 맞는건지요?

 

NOT EXISTS 에 대해서 좀 자세히 설명 부탁드립니다. (__)

이 글에 대한 댓글이 총 1건 있습니다.

1. db2 "select * from org"

DEPTNUMB DEPTNAME       MANAGER DIVISION   LOCATION    
-------- -------------- ------- ---------- -------------
      10 Head Office        160 Corporate  New York    
      15 New England         50 Eastern    Boston      
      20 Mid Atlantic        10 Eastern    Washington  
      38 South Atlantic      30 Eastern    Atlanta     
      42 Great Lakes        100 Midwest    Chicago     
      51 Plains             140 Midwest    Dallas      
      66 Pacific            270 Western    San Francisco
      84 Mountain           290 Western    Denver      

  8 record(s) selected.

 

2. db2 "export to org.ixf of ixf select * from org"

3. db2 "import from org.ixf of ixf replace_create into org_mirror"

4. db2 "delete from org_mirror where DEPTNUMB=10"

 

5. db2 "select * from org a where not exists(select * from org_mirror b where a.DEPTNUMB=b.DEPTNUMB)"

DEPTNUMB DEPTNAME       MANAGER DIVISION   LOCATION    
-------- -------------- ------- ---------- -------------
      10 Head Office        160 Corporate  New York    

  1 record(s) selected.

=> Estimated Cost = 26.194668
     Estimated Cardinality = 0.016667

 

    db2 "select * from org a where not exists(select 1 from org_mirror b where a.DEPTNUMB=b.DEPTNUMB)"

DEPTNUMB DEPTNAME       MANAGER DIVISION   LOCATION    
-------- -------------- ------- ---------- -------------
      10 Head Office        160 Corporate  New York    

  1 record(s) selected.

=> Estimated Cost = 26.194668
     Estimated Cardinality = 0.016667

 

두 sql이 하는일은 동일합니다.

 

 

도님이 2006-07-25 18:01에 작성한 댓글입니다.
이 댓글은 2006-07-26 15:17에 마지막으로 수정되었습니다. Edit
[Top]
No.
제목
작성자
작성일
조회
1061UPDATE와 JOIN [1]
아추워
2006-07-26
7916
1060JOIN 시에 이런 오류... [2]
2006-07-26
7415
1059db2 import와 load [1]
이문선
2006-07-26
9725
1058NOT EXISTS [1]
exists
2006-07-25
7935
1057Temp Tablespace,User tablespace 는 테이블스페이스단위로 백업이 불가능한가요? [1]
궁금이
2006-07-25
7341
1056import시에 로그가 안쌓이게 하는 방법은? [1]
이문선
2006-07-25
7218
1055날짜 (month)- 날짜(month) > 6 month [4]
김현철
2006-07-21
17751
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.021초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다