Home > database >  Exists in mysql and, in distinct difference
Exists in mysql and, in distinct difference

Time:09-21

Reference:
: https://blog.csdn.net/zhou920786312/article/details/72857527
Use the exists
Using the exists instead of in
1 exists only to check the existence, in to check the actual value, so existsd's performance is better than in
Verify
Select * from emp where deptno in (select deptno from dept where loc="NEW YORK"); Select * from emp e where the exists (select 1 from the dept d where d.d eptno=e.d eptno and loc='NEW YORK');


Using the exists instead of distinct
1 exists only to check the existence, distinct used to prohibit duplicate lines, and distinct needs sorting before prohibit duplicate lines show line of retrieval, and so the exists performance is better than distinct
Verify
Select distinct e.d eptno, d.d name from emp e, d dept where e.d eptno=d.d eptno; Select d.d eptno, d.d name from dept d where the exists (select 1 from emp where e e.d eptno=d.d eptno);

CodePudding user response:

Thanks for sharing, notes class knowledge suggest wrote blog
  • Related