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) 中没有匹配的行。
!!!!这里最终返回表里边谁在左谁在右一定要分清。
总结:![在这里插入图片描述](https://img-blog.csdnimg.cn/20190309130114931.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2h1anVhbjk0MDcwMw==,size_16,color_FFFFFF,t_70)
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也类似