0
Help me with a situation please, I need to get all the records of the table "buyer" and its attributes and if I have in the records of a client in the order table linked to some buyer listed it shows me by buyer:
comprador.nomeCompr,
comprador.descCatComprador,
COALESCE(sum(mercadoria.precoMercadoria*pedido.quantMercPedido),'0') as 'valorTotal',
COALESCE(sum(pedido.quantMercPedido),'0') as 'volumeTotal'
from comprador
join fornecedor on fornecedor.codComprFornecedor = comprador.codCompr
left join pedido on pedido.codFornPedido = fornecedor.codForn
left join mercadoria on mercadoria.codMercadoria = pedido.codMercPedido
where comprador.codCompr in (select codCompr from comprador)
and pedido.codAssocPedido = '4102'
group by comprador.codCompr order by valorTotal desc
But in this case he returns only the buyers who have ordered and not the ones who are zeroed, I would like him to return also the buyers who are zeroed, If I do not use the condition Where request.codAssocPedido = '4102' it returns all values including zeroes, but brings also clients I do not want to list, below the prints.
If you are already working with the buyer table in the most external SELECT why
where comprador.codCompr in (select codCompr from comprador)
? Won’t this always be true? As you have no restriction for customers for what reason says behind customers you don’t want to list?– anonimo
Actually I created this ambiguity purposely, but for example I am saying in the '''and request.codAssocPedido = '4102'''' line that it should pull only the associated "customer" actually from the order table
– user179791