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?