码迷,mamicode.com
首页 > 其他好文 > 详细

左连接和右连接

时间:2018-02-07 19:40:39      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:left join   blog   ace   连接   sel   gpo   结果   sele   convert   

1.左连接:只要左边表中有记录,数据就能检索出来,而右表的数据要在左边中有记录才能被检索出来。

左连接只影响右表

select *  from table1 left join tbale2 on table1.id = table2.id
这条sql语句返回结果   table1表中的数据全部返回   table2表中的数据只返回满足条件的

2.右连接:只要右表中有记录就能被检索出来。

右连接只影响左表

右链接   (right join)
    select * from table1 right join table2 on table1.id = table2.id
这条sql语句返回结果   table2表中的数据全部返回    table1表中的数据只返回满足条件的
 
3.(innert join)理解为“有效连接”,两张表中都有的数据才会显示left join:理解为“有左显示”,比如on a.field=b.field,则显示a表中存在的全部数据及a\\b中都有的数据,A中有、B没有的数据以null显示
    select * from table1 inner join table2 on table1.id = table2.id
这条sql语句返回结果   显示满足条件的数据   并不以谁为主表

左连接和右连接

标签:left join   blog   ace   连接   sel   gpo   结果   sele   convert   

原文地址:https://www.cnblogs.com/arvins/p/8427305.html

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