MySQL 关联查询  外连接 { LEFT| RIGHT } JOIN

时间:2018-06-13 22:55:01   收藏:0   阅读:249

左外连接: (以左表为基准)
两张表做连接的时候,在连接条件不匹配的时候
留下左表中的数据,而右表中的数据以NULL填充
例:使用左连接把学生的数据全取出来,该学生没有学院信息的用NULL填充

mysql>  select * from  student  left join  department
         ->  on dept_id= d_id;


右外连接: (以右表为基准)
对两张表做连接的时候,在连接条件不匹配的时候
留下右表中的数据,而左表中的数据以NULL填充
例:使用右外连接,把没有的学院的数据也显示出来
insert into department(d_name)  value(‘艺术学院’);

mysql>   select * from  student right join department
         ->   on dept_id= d_id;

原文:https://www.cnblogs.com/mariobear/p/9180542.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!