现在有A表(主表),结构和数据如下:serial_no xm00000000000194013768 时**
00000000000194005220 孟**
B表(从表),结构和数据如下:serial_no a_serial_no rq12010100050000000143 00000000000194005220
12010100050000000161 00000000000194005220 20070411
12010100050000000145 00000000000194013768 20070410用以下SQL文检索:select a.xm,
b.rq,
b.serial_no
from a,b
where a.serial_no = b.a_serial_no(+)
and b.rq(+) is null ; 结果如下:rownum xm rq serial_no 1 孟** 12010100050000000143
2 时** 可是我预想的结果却是:
rownum xm rq serial_no 1 孟** 12010100050000000143
2 时**
3 孟** 请问为什么我预想中的rownum:3没有出来?
如果条件不符合的话,那为什么rownum:2却能出来,
他们应该是一样的呀?
为什么rownum:1出来后,我预想的rownum:3就被过滤掉了?
00000000000194005220 孟**
B表(从表),结构和数据如下:serial_no a_serial_no rq12010100050000000143 00000000000194005220
12010100050000000161 00000000000194005220 20070411
12010100050000000145 00000000000194013768 20070410用以下SQL文检索:select a.xm,
b.rq,
b.serial_no
from a,b
where a.serial_no = b.a_serial_no(+)
and b.rq(+) is null ; 结果如下:rownum xm rq serial_no 1 孟** 12010100050000000143
2 时** 可是我预想的结果却是:
rownum xm rq serial_no 1 孟** 12010100050000000143
2 时**
3 孟** 请问为什么我预想中的rownum:3没有出来?
如果条件不符合的话,那为什么rownum:2却能出来,
他们应该是一样的呀?
为什么rownum:1出来后,我预想的rownum:3就被过滤掉了?
解决方案 »
- 如何解决left join 被关联表不能带条件的问题
- orcale存储工程提示错误
- Win7 x64 VS2010调Oracle数据库报错ORA-06413
- orcle 截取最后一位
- 导入DMP文件的一张表的时候 如果给这个表取别名?
- 请问记录对某个表的删除操作的触发器该怎么写?
- 如何定期修改某张表中的指定字段??
- 用dbms可以创建删除作业,但是运行有错???
- alter table table1 add (kyc number(20)); 出错了
- 请教个关于oracle alert trace日志的问题
- 安装数据库时的用户名和密码忘了
- oracle 中 SQL PLUS环境中使用某个数据库用什么命令啊
如果B表中的 [时**] 可以检索出来,
那么B表中的 [孟**,rq=20070411]应该也可以检索出来呀?
and b.rq(+) is null ; 有问题吧!这个+貌似是没用的
去掉这个就出3个结果了吧!
那么B表中的 [孟**,rq=20070411]应该也可以检索出来呀?这个结果的rq is not null
b.rq,
b.serial_no
from a,b
where a.serial_no = b.a_serial_no(+)
and b.rq(+) is null ;
等价于:
select a.xm, b.rq, b.serial_no
from a left join b on a.serial_no = b.a_serial_no and b.rq is null
也就是说a表左连接b表,看b表是否存在a.serial_no = b.a_serial_no and b.rq is null的纪录,如果存在,则显示相关的b表中的信息;否则,对a表中的纪录在b表中找不到纪录相匹配的话,则在查询出的结果集的对应字段中显示null,所以仅仅返回两条纪录,而不是楼主希望的3条纪录
b.rq(+) is null 不是不起作用,也不是b.rq is null
(1)... left join b on ... and b.rq is null
(2)... left join b on ...
where b.rq is null
上面两个查询的结果是不一样的,尽管可以多拿几条记录尝试一下
b.rq,
b.serial_no
from a,b
where a.serial_no = b.a_serial_no(+)
and b.rq(+) is null ; -> and b.rq is null
楼主还是没说这2个语句的结果有什么不同啊!
... and b.cgrq(+) is null 的结果:1 孟** 12010100050000000143
2 时** ... and b.cgrq is null 的结果: 1 孟兆友 12010100050000000143