Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Sql not exists
Kimberly,
But you were right in the first place ;-)
An outer join, with a little twist (line 4), can be used for anti-joins (item a not in b)
SQL> select d.deptno
2 from dept d, emp e
3 where d.deptno = e.deptno (+)
4 and e.deptno is null
5 /
DEPTNO
40
I don't see many people use the approach above, but, it is valid. It does confuse some people when they first see it. But if you really want to confuse folks and make the code a little more difficult to maintain, you can try some more obscure (or simply double negation) methods:
1 select d.deptno
2 from dept d, emp e
3 where not d.deptno <> e.deptno (+)
4* and not e.deptno is not null
SQL> /
DEPTNO
40
1 select deptno
2 from dept
3* where not deptno = any (select deptno from emp)
SQL> /
DEPTNO
40
1 select deptno
2 from dept
3* where deptno <> all (select deptno from emp)
SQL> /
DEPTNO
40
And has anyone provide a NOT IN example yet? We got the basics of MINUS, NOT EXISTS, and a null OUTER JOIN.
Regards,
Larry G. Elkins
elkinsl_at_flash.net
214.954.1781
> -----Original Message-----
> From: root_at_fatcity.com [mailto:root_at_fatcity.com]On Behalf Of Kimberly
> Smith
> Sent: Thursday, October 25, 2001 11:16 AM
> To: Multiple recipients of list ORACLE-L
> Subject: RE: Sql not exists
>
>
> Opps, I responding to this just a second ago and recommended outer join.
> Then I saw this response and it made me reread the question. Duh! More
> coffee please.
>
> -----Original Message-----
> Sent: Thursday, October 25, 2001 3:20 AM
> To: Multiple recipients of list ORACLE-L
>
>
> select id from table1
> minus
> select id from table2
>
> -----Original Message-----
> Sent: 25 October 2001 09:35
> To: Multiple recipients of list ORACLE-L
>
>
>
>
> Hallo you DBA'
>
> Can anyone give me a good example on a sql select statement checking which
> ids exists in table one but not in table two? Table two also contains the
> corresponding id field but with other field names besides. Like this
>
> Table 1: Id Name Year
> Table 2: :Id City Country
>
> Thanks in advance
>
> Roland Sköldblom
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Larry Elkins INET: elkinsl_at_flash.net Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Thu Oct 25 2001 - 11:18:55 CDT
![]() |
![]() |