mysql查询优化

select * from a where id in (select id from b)

等价于:

for select id from b

for select 8 from a where a.id = b.id

当b表数据必须小于a表数据时,in优于exists

select * from a where exists (select 1 from b where b.id = a.id)

等价于:

for select * from a 

for select * from b where b.id = a.id 

防止exists优于in

posted @ 2020-06-11 20:55  saber丶吾王  Views(181)  Comments(0Edit  收藏  举报