说起这两种联接方式,一定要把Right Join联系起来。
一、释义。
1、Left Join(左联接)
以左表为中心,返回左表中符合条件的所有记录以及右表中联结字段相等的记录——当右表中无相应联接记录时,返回空值。2、Right Join(右联接)
以右表为中心,返回右表中符合条件的所有记录以及左表中联结字段相等的记录——当左表中无相应联接记录时,返回空值。
3、Inner Join(等值连接)
返回两个表中联结字段相等的行。
二、示例。
1、插入测试表(test1,test2)
create table test1 --测试表1
(id int not null,
value char(10) )
create table test2 --测试表2
(id int not null,
value char(10) )
2、插入数据
--insert into test1
insert into test1
values (1,'testaa')
insert into test1
values (2,'testaa')
insert into test1
values (3,'testaa')
--insert into test2
insert into test2
values (1,'testaa2')
insert into test2
values (2,'testaa2')
insert into test2
values (4,'testaa2')
3、查询结果比较(附图)
select * from test1 a left join test2 b on a.id = b.id
select * from test1 a right join test2 b on a.id = b.id
select * from test1 a inner join test2 b on a.id = b.id
4、删除测试表
drop table test1
drop table test2
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有