Search
Winners

Win Prizes

Social Presence
Like us on Facebook
Advertisements
Ads

Improve Your Sql query Performance

Saranpselvam
Posted by Saranpselvam under Sql Server on 4/22/2014 10:06:03 AM | Points: 75 | Views : 2148 | Status : [Member]

HI 

For improving performance in your query we should not use "not in" . So how can we avoid not in? 

consider a situation there are two tables t1,t2 both having a common column called "book Name". if you want to get book name from t1 but those name should not being in t2 table then we should writ our query like the following 

Good practice 
----------------- 
SELECT t1.bookname 
FROM t1 
LEFT OUTER JOIN t2 
ON t1.bookname= t2.bookname 
WHERE t2.bookname IS NULL 

Bad Practice 
----------------- 
select t1.bookname from t1 where t1.bookname not in(select t1.bookname from t2) 


Thanks 
saranpselvam@gmail.com 
saran



Comments or Responses


Login to post response