I have the following query:
SELECT products_categories.categoryID, name, COUNT(*) AS itemCount
FROM products_categories
LEFT JOIN products_to_categories ON products_to_categories.categoryID = products_categories.categoryID
GROUP BY products_categories.categoryID
But still there's a problem: categories with no products in them return itemCount = 1
instead of 0
. How can I fix this?
Have you tried COUNT(products_to_categories.categoryID) AS itemCount
? I am not really sure but would think that maybe the problem lies in the COUNT(*)
.
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