首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

有个奇怪的有关问题。

2012-01-20 
有个奇怪的问题。。。select*fromawherea.idin(selectidfromb)select*fromawhereexists(selectidfromb)为何

有个奇怪的问题。。。
select   *   from   a   where   a.id   in(select   id   from   b);

select   *   from   a   where   exists(select   id   from   b);

为何这两个语句查出的结果不同??in   和exists结果有区别?

[解决办法]
select * from a where a.id in(select id from b);
相当于
select * from a where exists(select id from b wherea.id=b.id);
[解决办法]
select * from a where exists(select id from b where a.id=b.id);
--B表有id=a.id的数据才返回TRUE

select * from a where exists(select id from b);
--只要B表有数据就返回TRUE

热点排行