MySQL inner join 和 left join 的区别
看了网上一些讲的感觉还是云里雾里,不如自己实操一下。
sql语句,left join
select isad.type_id, isad.activity_id, isad.id, ist.type_name, f.status from inspection_store_activity_detail isad inner join inspection_store_type ist on isad.type_id = ist.id left join inspection_store_follow f on isad.id = f.activity_detail_id
inner join
select isad.type_id, isad.activity_id, isad.id, ist.type_name, f.status from inspection_store_activity_detail isad inner join inspection_store_type ist on isad.type_id = ist.id inner join inspection_store_follow f on isad.id = f.activity_detail_id
如图,inner join在连接的表在要查询的字段有空时,该条记录不会被查询出来,主表信息也不保留。
left join 是主表信息都保留,连接的表有该字段展示,没有就展示null。
下班记得打卡