码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2018-06-13 23:30:30      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:mysql   name   join   sql   dep   右外连接   外连接   查询   left join   

左外连接: (以左表为基准)
两张表做连接的时候,在连接条件不匹配的时候
留下左表中的数据,而右表中的数据以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;

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

标签:mysql   name   join   sql   dep   右外连接   外连接   查询   left join   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!