前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据库中内连接、外连接、全连接

数据库中内连接、外连接、全连接

作者头像
forrestlin
发布2022-04-02 09:49:57
4.4K0
发布2022-04-02 09:49:57
举报
文章被收录于专栏:蜉蝣禅修之道蜉蝣禅修之道

转自:http://blog.csdn.net/yilip/article/details/8065840

内连接:把两个表中数据对应的数据查出来 

外连接:以某个表为基础把对应数据查出来(全连接是以多个表为基础) 

student表 

no name 

1 a 

2 b 

3 c 

4 d 

grade表 

no grade 

1 90 

2 98 

3 95 

内连接 inner join(查找条件中对应的数据,no4没有数据不列出来) 

语法:select * from student inner join grade on student.no = grade.no 

结果 

student.no name grade.no grade 

1 a 1 90 

2 b 2 98 

3 c 3 95 

左连接(左表中所有数据,右表中对应数据,即左边一定有数据,右边不一定有) 

语法:select * from student left join grade on student.no = grade.no 

结果: 

student.no name grade.no grade 

1 a 1 90 

2 b 2 98 

3 c 3 95 

4 d 

右连接(右表中所有数据,左表中对应数据,即右边一定有,左边不一定有) 

语法:select * from student right join grade on student.no = grade.no 

结果: 

student.no name grade.no grade 

1 a 1 90 

2 b 2 98 

3 c 3 95 

全外连接(表中数据=内连接+左边缺失数据+右边缺失数据)

语法:select * from student full join grade on student.no = grade.no  结果:  no name grade  1 a 90  2 b 98  3 c 95  4 d  1 a 90  2 b 98  3 c 95 

交叉连接(没有where字句时结果为笛卡尔积)

   一般不用。

注:access 中不能直接使用full join ,需要使用union all 将左连接和右连接合并后才可以

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

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