select 1 from b where b.id = a.id和 select 1 from a where b.id = a.id有区别么?

select 1 from b where b.id = a.id和 select 1 from a where b.id = a.id有区别么?
请问他们有区别么?
举个例子:
select * from b where exists (select 1 from a where a.c=b.c)
select * from b where exists (select 1 from b where a.c=b.c)
这两句有区别么?
(高效)SELECT * FROM  EMP (基础表)  WHERE  EMPNO > 0  AND  EXISTS (SELECT ‘X’  FROM DEPT  WHERE  DEPT.DEPTNO = EMP.DEPTNO  AND  LOC = ‘MELB’) 
(低效)SELECT  * FROM  EMP (基础表)  WHERE  EMPNO > 0  AND  DEPTNO IN(SELECT DEPTNO  FROM  DEPT  WHERE  LOC = ‘MELB’) 
选的表不同,你的例子,第一个是从b表选a.c=b.c的数据,第二个是从a表选。就好像a有3个c=1,b有1个c=1,你说从不同表选c=1结果一样不?就这意思。 
其实你的:select * from b where exists (select 1 from a where a.c=b.c)
等价于:select * from b where b.c IN (select a.c from a where a.c=b.c)
可能用下面这句容易看懂些。就是从b表中查找与a表有相同字段c的所有结果集。

————————————————
版权声明:本文为CSDN博主「我们都一样w」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_33307908/java/article/details/79534425

posted @ 2020-04-23 21:56  天涯海角路  阅读(429)  评论(0)    收藏  举报