ITPub博客

首页 > 数据库 > Oracle > 两表关联实验

两表关联实验

原创 Oracle 作者:jlliuyi 时间:2009-11-09 16:39:25 0 删除 编辑
原创[@more@]
两表关联实验

create table test1(a integer,b integer);
create table test2(a integer,b integer);
insert into test1 values(1,11);
insert into test1 values(2,22);
insert into test1 values(3,33);
insert into test1 values(4,44);


insert into test2 values(1,11);
insert into test2 values(2,22);
insert into test2 values(3,33);


select * from test1,test2 where test1.a(+)=test2.a;
SQL> select * from test1,test2 where test1.a=test2.a(+);

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33
4 44

select * from test1,test2 where test1.a(+)=test2.a;
SQL> select * from test1,test2 where test1.a(+)=test2.a;

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33

select * from test1 left join test2 on test1.a=test2.a;
相当于select * from test1 left outer join test2 on test1.a=test2.a;
SQL> select * from test1 left join test2 on test1.a=test2.a;

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33
4 44

select * from test1 right join test2 on test1.a=test2.a;
相当于select * from test1 right outer join test2 on test1.a=test2.a;
SQL> select * from test1 right join test2 on test1.a=test2.a;

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33

select * from test1 left outer join test2 on test1.a=test2.a;
相当于select * from test1 left join test2 on test1.a=test2.a;
相当于select * from test1,test2 where test1.a=test2.a(+);
SQL> select * from test1 left outer join test2 on test1.a=test2.a;

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33
4 44

select * from test1 right outer join test2 on test1.a=test2.a;
相当于select * from test1 right join test2 on test1.a=test2.a;
相当于select * from test1,test2 where test1.a(+)=test2.a;
SQL> select * from test1 right outer join test2 on test1.a=test2.a;

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33

select * from test1 inner join test2 on test1.a=test2.a;
相当于:select * from test1,test2 where test1.a=test2.a;
SQL> select * from test1 inner join test2 on test1.a=test2.a;

A B A B
---------- ---------- ---------- ----------
1 11 1 11
2 22 2 22
3 33 3 33

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8007125/viewspace-1028573/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有硝烟的战场
下一篇: 没有了~
请登录后发表评论 登录
全部评论
  • 博文量
    105
  • 访问量
    84437