五、多表连接查询——外连接
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