exists的问题

tjm1 2005-01-28 01:10:10
a 表:

a b
------
1 a
2 b
3 c

aa 表:

a b
-------
1 w
2 x
3 y
4 z ------用exists把这条记录查出来

要求用exists把aa表的第4条记录查询出来,
我用下列语句不好用,
select a from a where not exists (select a from aa);
or
select * from a where not exists (select * from aa);
应该怎么写?exists对选择的字段还有要求吗?
...全文
184 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
soniczck 2005-01-30
  • 打赏
  • 举报
回复
用EXISTS时,它只返回TRUE 或 FALSE,如果子查询返回的内容为非空时,EXISTS 返回TRUE 否则返回FALSE。你的语句的子查询为TRUE,所以你的语句永远都没有记录。

select * from aa where not exists(select * from a where aa.a=a.a);
一杯清茶Kevin 2005-01-29
  • 打赏
  • 举报
回复
来晚了!
zlindong 2005-01-29
  • 打赏
  • 举报
回复
正确的做法
select * from aa where not exists(select * from a where aa.a=a.a);
这样就可以得到你要的结果了!
zlindong 2005-01-29
  • 打赏
  • 举报
回复
exists在子查询中过滤某些行,因此你那样不对。
liuyi8903 2005-01-29
  • 打赏
  • 举报
回复
给点分吧:(
cl2_oracle 2005-01-29
  • 打赏
  • 举报
回复
mark
yxxx 2005-01-28
  • 打赏
  • 举报
回复
SQL> select * from aa
2 where not exists(select * from a where aa.a=a.a)
3 ;

A B
---------- ----------
4 z

经测试,正确:)
luckbird 2005-01-28
  • 打赏
  • 举报
回复
来晚了
yxxx 2005-01-28
  • 打赏
  • 举报
回复
select * from aa
where not exists(select * from a where aa.a=a.a)
wupangzi 2005-01-28
  • 打赏
  • 举报
回复
select * from a where not exists (select * from aa where a.a = aa.a);

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧