left jon on 条件失效

1.left jon on 条件失效 ,原sql,会导致a的记录全部查出来,and 条件没有起作用

select  a.id,a.name,b.address,c.math
      from tablea a left join tableb b 
      on a.id = b.id
      and  a.name like "%mi%"
      left join tablec c 
      on a.id = c.id


改进sql 在最后用where来进行处理,还有条件的话加and

select  a.id,a.name,b.address,c.math
      from tablea a left join tableb b 
      on a.id = b.id
      left join tablec c 
      on a.id = c.id
      where  a.name like "%mi%"

 
 

猜你喜欢

转载自blog.csdn.net/qq_22222499/article/details/80261452
今日推荐