【fromb】select1frombwhereb.id=a.id和select1fromawhereb.id=....

发布时间:2021-04-05 06:36:01

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)这两句有区别么?

网友回答

【答案】 选的表不同,你的例子,第一个是从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的所有结果集。
以上问题属网友观点,不代表本站立场,仅供参考!