I have this code, works well.

I want it to only show records where TTL is greater than 0.

If I add "AND TTL > 0 " in the WHERE clause, it errors. Help please.

SELECT p.ID, p.ProductName, p.Image, COUNT(*) as `TTL`

FROM `products` p 
JOIN `inventory` i ON p.ID = i.ProductID

WHERE i.DateAdded > 0  AND p.ProductStatus = 0 AND p.ID != 60 

GROUP By p.ID

    Because the WHERE clauses are evaluated before the grouping. Grouping is done before aggregate functions (like COUNT).
    You want a HAVING clause.

    And as I mentioned on webdeveloper forums, why would COUNT(*) ever be zero?

      Write a Reply...