參考:
:https://blog.csdn.net/zhou920786312/article/details/72857527
使用exists
使用exists代替in
1exists只檢查行的存在性,in 檢查實際的值,所以existsd的性能比in好
驗證
select * from emp where deptno in(select deptno from dept where loc='NEW YORK'); select * from emp e where exists(select 1 from dept d where d.deptno=e.deptno and loc='NEW YORK');
使用exists代替distinct
1exists只檢查行的存在性,distinct用于禁止重復行的顯示,而且distinct在禁止重復行的顯示前需要排序檢索的行,所以exists的性能比distinct好
驗證
select distinct e.deptno,d.dname from emp e,dept d where e.deptno=d.deptno; select d.deptno,d.dname from dept d where exists(select 1 from emp e where e.deptno=d.deptno);
uj5u.com熱心網友回復:
感謝分享, 筆記類知識 建議寫到博客
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/61957.html
標籤:新技術前沿
上一篇:Navicat安裝后,鏈接mysql資料庫出現 Can't connect to local MySQL server through socket
下一篇:flip viewer閱讀器
