首页 > Linux操作系统 > Linux操作系统 > a=b and b=c 问题
以前我们举例说明oracle进行自动扩展时,可能会有这样的例子:
如果连接条件中出现a=b and b=c,那么oracle自动推断出a=c。
例子本身是没有问题的,但这样的推断似乎不太严谨。
今天的工作中就遇到了一个类似的问题,因此自己实验一下:
首先,我在自己数据库的scott.emp和dept表中各添加了一条记录:
insert into dept values('28','','');
insert into emp values('100','tian','hunt','','','8800','28');
然后创建三张表,用来模拟场景:
create table emp_1 as select * from emp where deptno<>'10';
create table emp_2 as select * from emp where deptno<>'20';
create table emp_3 as select * from emp where deptno<>'30';
然后我们执行查询语句:
select a1.ename,a3.deptno,a3.sal from emp_1 a1,emp_2 a2,emp_3 a3
where a1.empno=a2.empno
and a2.empno=a3.empno
如果按照以上a=c的推断,应该得到的是除部门号为10、30的记录,而实际结果是:
ENAME DEPTNO SAL
1 tian 28 8800.00
a=b and b=c 其实是三张表的交集,而并非a、c的交集。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26451536/viewspace-747047/ ,如需转载,请注明出处,否则将追究法律责任。