1. 程式人生 > >mysql not in 或 in 優化

mysql not in 或 in 優化

在MySQL 中,not in 或in 優化思路, 利用left join 來優化,類似如下的查詢方式:

select id  from  a  where id  in  (select  id from b  )
如這樣的查詢方式,在大資料量的情況下,查詢很慢,需要改寫優化sql,那麼就可以用left join來優化改寫如下格式:
select id from a left join b on a.id =b.id  where b.id is not null 
其實優化思想就是利用join 連線,提高效率。
left join 的理解使用 ,參照另一篇文章 《 MySQL LEFT JOIN 語法用法與例項(二)》

not in 優化方式類似。

轉載地址:http://blog.csdn.net/aeolus_pu/article/details/7800699