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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 better performance - NOT in or Join

Author  Topic 

subhaoviya
Posting Yak Master

135 Posts

Posted - 2012-10-09 : 05:34:49
Hi,

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?

sql-programmers
Posting Yak Master

190 Posts

Posted - 2012-10-09 : 05:41:30
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
http://www.sql-programmers.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-09 : 23:12:33
what all indexes you've on table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -