0
Consider the following fictitious tables:
Venda = id_venda, data, id_carrinho
Carinho = id_carrinho
ItemCarrinho = id_item, id_carrinho, id_produto
Suppose there is 1 registration for sale, 1 registration in cart and 2 records in itemCarrinho
.
If I do this select
down below:
select count(b.id_carrinho) as qtd from Venda as a, Carrinho as b,
ItemCarrinho as c where a.id_venda = 1 and b.id_carrinho =
a.id_carrinho and c.id_carrinho = b.id_carrinho
it returns me counted in Qtd the value 2, and the correct one would be 1. How to fix this?
Possible duplicate of 2 Groupby in a Mysql query
– Augusto Vasques
Maybe you can leave the junction with the table Itemcarrinho but, if the logic of your application does not allow, you can also use: COUNT(DISTINCT b.id_carrinho).
– anonimo