mysql - show all rows from left join -


i have query

select if(viaturas.transportador null,        'sem transportador', viaturas.transportador) transportador,        sum(ifnull(retorno_euro,0))- sum(ifnull(devolucao_euro,0)) total_euro,        sum(ifnull(retorno_ddf,0))- sum(ifnull(devolucao_ddf,0)) total_ddf,        sum(ifnull(retorno_vadias_plast,0))- sum(ifnull(devolucao_vadias_plast,0)) total_plast transportes.transportation_order     left join transportes.viaturas on viaturas.viatura=transportation_order.viatura estado not in ('cancelado', 'eliminado')   , servico in ('distribuição', 'devolução', 're-entrega')   , data >= '2016-08-08' group lower(transportador); 

but shows result matched rows. how can show "tranportador" rows when there no match between tables?

when left join, put right side table conditions in on clause true left join behavior. (when in where clause, you'll regular inner join result.)

select if(viaturas.transportador null,        'sem transportador', viaturas.transportador) transportador,        sum(ifnull(retorno_euro,0))- sum(ifnull(devolucao_euro,0)) total_euro,        sum(ifnull(retorno_ddf,0))- sum(ifnull(devolucao_ddf,0)) total_ddf,        sum(ifnull(retorno_vadias_plast,0))- sum(ifnull(devolucao_vadias_plast,0)) total_plast transportes.transportation_order     left join transportes.viaturas on viaturas.viatura=transportation_order.viatura   , estado not in ('cancelado', 'eliminado')   , servico in ('distribuição', 'devolução', 're-entrega')   , data >= '2016-08-08' group lower(transportador); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -