外连接(outer join):left join、right join、full join
left join(左边的表不加限制):以左边的表作为基表,基表内容全部显示,再加上两张表匹配的内容。如果基表的内容在另一张表没有记录,则显示null
select* from test a left join test2 b on a.id=b.id;
right join(右边的表不加限制):以右边的表作为基表,基表内容全部显示,再加上两张表匹配的内容。如果基表的内容在另一张表没有记录,则显示null
full join(两边的表都不限制)
创建两张表:
create table test(
id umber(10) not null,
name archar2(20),
sex archar2 (8),
email archar2 (20)
)
create table test2(
id number(10) not null,
name varchar2(20),
tel varchar2 (11)
)
left join:
select * from test a left join test2 b on a.id=b.id;
right join:
select * from test a right join test2 b on a.id=b.id;
full join:
select * from test a full join test2 b on a.id=b.id;
select * from test2 a full join test b on a.id=b.id;