前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >inner join和left join的区别

inner join和left join的区别

作者头像
多凡
发布2019-11-01 09:02:29
2.8K0
发布2019-11-01 09:02:29
举报
文章被收录于专栏:sringbootsringboot

说起这两种联接方式,一定要把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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-05-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档