小表驅動大表


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM