五、多表连接查询——外连接

五、多表连接查询——外连接

1.左外连接

简单来说,就是在等值连接的基础上,保留左侧表的独有数据,右表没有的用null替代。

2.右外连接

简单来说,就是在等值连接的基础上,保留右侧表的独有数据,左表没有的用null替代。

select * from student right join student_score on student.student_id=student_score.student_id;

3.全外连接

保留各自表中独特的部分。

Mysql暂不支持全外连接,可采用其它方式替代:使用union关联两个表的结果即全外连接。

union会整合多个查询结果到一个表中。

select * from student left join student_score on student.student_id=student_score.student_id
union
select * from student right join student_score on student.student_id=student_score.student_id;


解锁课程,学习更多mysql知识:
https://study.163.com/course/courseMain.htm?courseId=1209590958&share=2&shareId=400000000537035

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值