A表表结构
create table A
(
ids varchar2(32),
names varchar2(32)
)
B表表结构同A一模一样.
初开化数据
insert into A values('1','1');
insert into A values('2','2');
insert into A values('3','3');insert into B values('1','A');
insert into B values('2','B');
insert into B values('3','C');
insert into B values('4','D'); select * from A a where exists (select ids from B where a.ids = '2');查询的结果我预期为A表整个表的值,但是我无意写错查询出的结果却是
2,2
如果我改成
select * from A a where exists (select ids from B where a.ids = '1');
结果是
1,1请高手解释一下,越详细越好
create table A
(
ids varchar2(32),
names varchar2(32)
)
B表表结构同A一模一样.
初开化数据
insert into A values('1','1');
insert into A values('2','2');
insert into A values('3','3');insert into B values('1','A');
insert into B values('2','B');
insert into B values('3','C');
insert into B values('4','D'); select * from A a where exists (select ids from B where a.ids = '2');查询的结果我预期为A表整个表的值,但是我无意写错查询出的结果却是
2,2
如果我改成
select * from A a where exists (select ids from B where a.ids = '1');
结果是
1,1请高手解释一下,越详细越好
解决方案 »
- orcale 关于update的表连接SQL语句
- 断电的时候,为什么需要先undo然后再redo呢,redo与undo有啥联系?
- 触发器编写:保留最新20条记录
- 请教下大家学习oracle 的经验,我想有了大家的帮助我可以少走弯路。
- 添加优化索引的问题
- oracle的8080端口问题
- 为什么在执行建TRIGGER语句的时候会有Cannot create triggers on objects owned by SYS这样的提示?
- 急!关于基于函数的索引,我该如何写?
- 嵌套查询和连接的区别?????????????????
- oracle8.1.7+Red Hat Linux安装
- undo表空间的增长比例是怎么样的(急!)?
- create session权限与connection权限有什么不同啊
首先你要理解这是一个关联子查询 因为在子查询中使用到了a.ids2
语句执行的时候 遍历表A 拿每个ids去和'2'比较
当A表中的1,1和3,3两条去比时条件a.ids='2'为false 因此子查询select ids from B where a.ids = '2'不会返回任何结果 exists子句返回也就相当于false 这个时候外层select * from A不返回结果
只有2,2这条记录符合条件 因此返回了2,2