mysql exists与in的区别

select * from user where exists (select * from order where user.id = order.user_id)

exists会先查前面的表(user)  然后再和后面的表(order)关联筛选出结果

select * from user where in (select user_id from order)

in会先查后面的表(order)然后再和前面的表(user)关联筛选出结果

 

所以外层的表数据量大的时候使用in,反之则用exists

posted on 2017-08-09 17:17  长风剑客  阅读(190)  评论(0编辑  收藏  举报

导航