ITPub博客

首页 > 数据库 > Oracle > 左右内全连接

左右内全连接

原创 Oracle 作者:ygz752066641 时间:2014-06-19 11:54:00 0 删除 编辑

--Oracle左右内全连接--

--建立测试数据
create table a (id number);
create table b (id number);
create table c (id number);

insert into a values(1);
insert into a values(2);
insert into a values(3);
insert into b values(1);
insert into b values(2);
insert into b values(4);
insert into c values(1);
commit;

--注:编写SQL时,outer关键字可省略;

--右向外连接,right outer join;返回右表等值的基础上加上被连接表不匹配的数据;
select * from a right join b on a.id=b.id;
select * from a,b where a.id(+)=b.id;

--左向外连接,left outer join;  返回左表等值的基础上加上被连接表不匹配的数据;
select * from a left join b on a.id=b.id;
select * from a,b where a.id=b.id(+);

--内向连接,和where相同;返回左右等值的数据;
select * from a inner join b on a.id=b.id;
select * from a,b where a.id=b.id;

--全连接,返回等值的的基础上加上左右表未匹配的数据;
select * from a full join b on a.id=b.id;
select * from a,b where a.id=b.id(+) union select * from a,b where a.id(+)=b.id;

--完全连接(交叉连接),笛卡尔积;
select * from a,b;
select * from a cross join b;

--左向外连接,后面加条件,返回符合条件的左连接;
select * from a,b where a.id=b.id(+) and b.id=2;

--在where上加第二个加号,它的作用是用来修改右边表的显示记录,如b.id(+)=2,则显示2,否则显示null;
select * from a,b where a.id=b.id(+) and b.id(+)=2;

--三个表做左向外连接
select * from a ,b,c where a.id=b.id(+) and a.id=c.id(+);

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

上一篇: 通用的时间函数
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2014-01-09

  • 博文量
    2
  • 访问量
    1133