I have a problem in counting by MySQL in a GROUP BY
This is the query that does not return the desired result.
SELECT COUNT(bagno)
FROM disposizione_assegnazione_pezze
JOIN pezze
ON pezza = id
WHERE id_prodotto_tessuto = 12096
AND id_collezione = 11
AND id_stagione = 22
AND id_tema = 1
GROUP BY bagno
The result of the count is 3
This is the pezza
table and its primary key is id
This is the table disposizione_assegnazione_pezze
that has the pezza
column which refers to the previous table
Why does not return 1 as a result my query?
I want to count how many different bagno
are there
I dont think you need GROUP BY
, instead use DISTINCT
SELECT COUNT(DISTINCT bagno)
SQL DEMO
Check your query without agregatted function COUNT/GROUP BY
As you can see bagno = 55
appear three times, that is why when you group by bagno
and count get 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With