Oracle外连接 - 需要了解它的工作原理

时间:2014-06-24 08:58:40

标签: oracle

请考虑以下命令:

create table t1 (
column1 number(10,2),
column2 number(10, 2),
column3 number(10, 2)
);

create table t2 (
column1 number(10,2),
column2 number(10, 2),
column3 number(10, 2),
column4 number(10, 2)
);

create table t3 (
column1 number(10, 2)
);

insert into t1 values (1, 2, 3);
insert into t1 values (4, 5, 6);
insert into t1 values (7, 8, 9);
insert into t1 values (10, 11, 12);
insert into t1 values (13, 14, 15);
insert into t1 values (16, 17, 18);


insert into t2 values (21, 22, 23, 1);
insert into t2 values (24, 25, 26, 1);
insert into t2 values (27, 28, 29, 1);

insert into t3 values (1);
insert into t3 values (4);
insert into t3 values (7);
insert into t3 values (10);
insert into t3 values (13);
insert into t3 values (16); 
insert into t3 values (21); 
insert into t3 values (24); 
insert into t3 values (27); 

select * from t1;
select * from t2;
select * from t3;

select t1.* 
from   t1, t2, t3
where  t1.column1 = 16
and    t2.column1= 24
and    (t1.column1 = t3.column1 or t2.column1 = t3.column1);

Result:

Column1 Column2 Column3
16      17      18
16      17      18

select t1.* 
from   t1, t2, t3 t31, t3 t32
where  t1.column1 = 16
and    t2.column1= 24
and     t1.column1 = t31.column1 (+)
and    t2.column1 = t32.column1 (+) ;

Result:
Column1 Column2 Column3
16      17      18

问题: 1.为什么query2只返回一行? 2.我需要了解这个查询如何执行的内部结构以及为什么它只返回一行? 请帮助我理解这一点。

0 个答案:

没有答案