Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: NOT IN is very inefficient

Re: NOT IN is very inefficient

From: Marc Billiet <Marc.Billiet_at_hae.hydro.com>
Date: 1998/09/25
Message-ID: <360B2BAA.4F9E@hae.hydro.com>#1/1

Steve Koterski wrote:
>
> On Thu, 24 Sep 1998 22:06:41 GMT, bjohnsto_usa_net_at_my-dejanews.com wrote:
>
> >SELECT my_field FROM my_table1
> >WHERE my_field NOT IN
> > (SELECT my_field FROM my_table2)
> >
>
> SELECT T1.my_field
> FROM my_table1 T1
> LEFT OUTER JOIN my_table2 T2
> ON (T1.my_field = T2.my_field)
> WHERE (T2.my_field IS NULL)
>

For Oracle that would be then:

SELECT T1.my_field
FROM my_table1 T1, my_table2 T2
WHERE T1.my_field = T2.my_field(+)
AND T2.rowid IS NULL

Yet another possibility (I've discovered that such a construction is sometimes faster when both tables are on different instances, i.e. via a database link; it is SLOWER when used against local tables):

SELECT my_field
FROM my_table1_at_database1
MINUS
SELECT my_field
FROM my_table2_at_database2

Marc Received on Fri Sep 25 1998 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US