直接上案例,不啰嗦,懂的都懂~
1, 新建左表tab_L 右表 tab_R:
左表: create table tab_L( test_L varchar2(10) )
右表: create table tab_R( test_R varchar2(10) )
2, 添加数据左表
insert into tab_L values(‘1’);
insert into tab_L values(‘2’);
insert into tab_L values(‘3’);
insert into tab_L values(‘4’);
insert into tab_L values(‘5’);
3, 添加数据右表
insert into tab_R values(‘4’);
insert into tab_R values(‘5’);
insert into tab_R values(‘6’);
insert into tab_R values(‘7’);
insert into tab_R values(‘8’);
4:查询左表数据:select * from tab_L
5:查询右表数据:select * from tab_R
inner join 内连接 : 查询相匹配部分,比如左右表都有的4,5
案例1
select l.test_L,r.test_R
from tab_L l
inner join tab_R r on r.test_r= l.test_l
查询结果:
left join 左连接 : 以左表为主,全部输出。右表匹配到的就输出,没匹配到的就为空。
案例2
select l.test_L,r.test_R
from tab_L l
left join tab_R r on r.test_r= l.test_l
查询结果:
right join 右连接 : 以右表为主,全部输出。左表匹配到的就输出,没匹配到的就为空。
案例3
select l.test_L,r.test_R
from tab_L l
Right join tab_R r on r.test_r= l.test_l
查询结果:
full join 全连接 : 全部输出。
案例4
select l.test_L,r.test_R
from tab_L l
full join tab_R r on r.test_r= l.test_l
查询结果: