sql语句优化:用join取代not in
不要太多使用not in查询,最好用表连接来取代它。如:
select ID,name from Table_A where ID not in (select ID from Table_B)
这句是最经典的not in查询了。改为表连接代码如下:
select Table_A.ID,Table_A.name from Table_A left join Table_B on Table_A.ID=Table_B.ID and Table_B.ID is null
或者:
select Table_A.ID,Table_A.name from Table_A left join Table_B on Table_A.ID=Table_B.ID where Table_B.ID is null
文章出自:http://www.cnblogs.com/rising-fay/archive/2012/11/13/2767538.html