天天看点

IN的相关子查询用EXISTS代替--sql2000性能优化

参考文章:SQL SERVER性能优化综述(很好的总结,不要错过哦)

数据库:系统数据库pubs

IN的相关子查询用EXISTS代替,比如:

SELECT PUB_NAME FROM PUBLISHERS 
                WHERE PUB_ID IN (
                      SELECT PUB_ID 
                       FROM TITLES 
                        WHERE TYPE = 'BUSINESS') 
           

改进如下:

SELECT PUB_NAME  FROM PUBLISHERS 
WHERE EXISTS (
     SELECT 1 
     FROM TITLES 
     WHERE TYPE = 'BUSINESS' AND  PUB_ID= PUBLISHERS.PUB_ID) 
           

继续阅读