Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 better performance - NOT in or Join
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

135 Posts

Posted - 10/09/2012 :  05:34:49  Show Profile  Reply with Quote

I am having query

SELECT * from Table1 where ID not in
(SELECT ID from Table2)

which have million of records Table1 and thousands of records in Table2.

for executing this query it taken more than 10 min

How to fast it up?

Posting Yak Master

190 Posts

Posted - 10/09/2012 :  05:41:30  Show Profile  Visit sql-programmers's Homepage  Reply with Quote
Please try this and update I hope which will help you.

SELECT * from Table1
LEFT JOIN Table2 ON Table2.ID = Table1.ID
Where Table2.ID IS NULL

I think, JOIN will be better than NOT IN.

SQL Server Programmers and Consultants

Edited by - sql-programmers on 10/09/2012 05:43:44
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/09/2012 :  23:12:33  Show Profile  Reply with Quote
what all indexes you've on table?

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000