join
left join,right join,inner join:
例子:select * from table1 as t1 left join table2 as t2 where t1.no = t2.no;
left join 关键字会从左表 (t1) 那里返回所有的行,即使在右表 (t2) 中没有匹配的行。
!!!!这里最终返回表里边谁在左谁在右一定要分清。
总结:
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 ;

right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录:
select * from table1 as t1 right join table2 as t2 where t1.no = t2.no;

inner join(等值连接) 只返回两个表中联结字段相等的行;
select * from table1 as t1 inner join table2 as t2 where t1.no = t2.no;
自然交: 根据左右两表的相同列创建一个隐含的join操作,相同列就是两表中列名相同的两列。自然交可以是内交,左交或者是右交。默认是内交。
最后,
left join是left outer join的缩写
right join与right outer join的区别也类似
join 与 inner join也类似
581

被折叠的 条评论
为什么被折叠?



