Roy Harper
Coder
I have a product categories listed in my website. But, I don't want to show categories that has 0 products under it, as you can see in the image below.
Here is my code:
[CODE lang="sql" title="SQL Select"]SELECT
c.category AS category,
(SELECT
COUNT(*)
FROM products AS p
WHERE p.categoryID = c.categoryID
) AS total_products
FROM categories AS c[/CODE]
Here is my code:
[CODE lang="sql" title="SQL Select"]SELECT
c.category AS category,
(SELECT
COUNT(*)
FROM products AS p
WHERE p.categoryID = c.categoryID
) AS total_products
FROM categories AS c[/CODE]