1.连接查询分为: inner join(自然连接,自连接) Left join(左连接)/Left outer join(左外连接):效果一样 Right join(右连接)/Right outer join(右外连接):效果一样 Full join(全连接)/Full outer join (全外连接) 2.大致语法如下: select a.*,b.* from table_3 as b FULL join table_2 as a on a.id=b.Mtype --左连接 select…
左连接查询在开发中很常用,但有个问题常常会遇到,两个表中有同名字段时,比如左右表都有一个id字段,会造成查询结果中左表的id值被右表的id值覆盖掉(大部分php框架都是这个效果),而且还不会报错,容易留下隐蔽的bug!解决办法很简单,给同名字段用AS起别名.例如:order表,farmer表都含有id字段, $sql ="SELECT *,i.`id` AS sid from hr_users_identity as i left join hr_student as s on i.`user_…
join :取两个表的合集: left join:左表的数据全部保留,然后增加右表与左表条件匹配的记录.如下 select cc.* from cloud_groups as cg left join cloud_contacts as cc on cg.ou=cc.departmentNumber order by cast(cg.sort as int),cast(cc.sort as int) //先以部门排序,再以员工进行排序 效果: (1)cloud_groups 的内的数据全部保留…