-- 创建表
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;