RE: Simple SQL Query

From: Michael McMullen <>
Date: Thu, 7 Jan 2010 12:33:12 -0500
Message-ID: <SNT130-ds40D154E7842C3E8276EE4A6710_at_phx.gbl>

You can write a query with a join as a

Not in

Not exists

Outer join  

The not exists has been discussed, the outer join would be



First a, second b


a.first_id = b.second_id(+)


b.second_id is null  

I always rewrite the queries the three different ways and explain plan all three and look at the differences. The key is to have up to date stats and either join on primary keys or indexed columns with not null constraints. You want oracle to be scanning an index not doing a full table join.  

From: [] On Behalf Of Pani Babu
Sent: Thursday, January 07, 2010 12:04 PM To:
Subject: Simple SQL Query  

I have a simple SQL query which lists all the records that are not in a second table.

select from first
where not in (select id from second);

As the second table is very huge, it takes a very long to process the query. Is there a way to rewrite the query to run it quicker?

Received on Thu Jan 07 2010 - 11:33:12 CST

Original text of this message