`

SQL 优化

阅读更多

1 不要使用 where not in,尤其是在表的数据量比较大时!
替代方案:
http://stackoverflow.com/questions/16901755/alternative-of-not-in-on-mysql
引用
select a.id
from A a
where a.user_id not in
(
select b.user_id from B b
)
方案一:使用 left outer join:
select a.id
from A a
left join B b on a.user_id = b.user_id
where b.id is null
方案二:使用 NOT EXISTS:
待加。。。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics