内连接、外链接、自然连接、全连接

oracle sql的连接类型有:

  • 内连接(inner join也叫join)
  • 外链接:分为 左连接left join 、 右连接right join
  • 自然连接:natrue join。特点:连接后的结果表中匹配的列只有一个
  • 全连接:(full join)。原理是先left join,再right join,然后把两个结果集 union。

实验

-- 创建表
create table test_a(
    id varchar2(32),
    name varchar2(1024)
);
insert into  test_a values ('1','张三');
insert into  test_a values ('2','李四');
insert into  test_a values ('3','王武');

create table test_b(
    id varchar2(32),
    job varchar2(1024),
    parent_id varchar2(32)
);

insert into test_b values ('1','23','1');
insert into test_b values ('2','34','2');
insert into test_b values ('3','34','4');

select * from test_a;

select * from test_b;


-- 内连接 join 或者 inner join
select * from test_a a join test_b b on a.id = b.parent_id;
select * from test_a a inner join test_b b on a.id = b.parent_id;

-- 左连接
select * from test_a a left join test_b b on a.id = b.parent_id;

-- 右链接
select * from test_a a right join test_b b on a.id = b.parent_id;

-- 全链接 full join
select * from test_a a full join test_b b on a.id = b.parent_id;

select * from
(select * from test_a a left join test_b b on a.id = b.parent_id)
union
(select * from test_a a right join test_b b on a.id = b.parent_id);

-- 疑问?为什么列明会变了?而且顺序也不一样了

-- 疑问?什么是外链接(使用可以看出来,外链接,就是左连接/右链接/全链接 简称)
select * from test_a a left outer join  test_b b on a.id = b.parent_id;
select * from test_a a right outer join  test_b b on a.id = b.parent_id;
select * from test_a a full  outer join  test_b b on a.id = b.parent_id;
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿hww

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值