小表驱动大表

1.为什么使用小表驱动大表

  小表驱动大表,小的数据集驱动大的数据集

  因为连接比较消耗时间

  所以,小表写在先查询的地方

select * from employee where id in (select id from department)

  

2.exists

select * from employee e where id exists (select 1 from department d where e.id = d.id)

  

3.in与exists

  区别:

  in是小表驱动大表

  exists是大表驱动小表

  说明:

  在上面的2中,department的数据量大于employee,所以使用exists

原文地址:https://www.cnblogs.com/juncaoit/p/13377768.html