mySQL JOIN wont return results with 0 count

Posted by MPC on Stack Overflow See other posts from Stack Overflow or by MPC
Published on 2011-06-24T21:38:45Z Indexed on 2011/06/25 8:22 UTC
Read the original article Hit count: 139

Filed under:
SELECT categories.*, COUNT(categoryID) AS kritCount
FROM categories AS categories
LEFT JOIN krits ON categories.id = categoryID
WHERE (krits.approved = '1')
GROUP BY categories.id

So this works great except that it does not return a category that has a 0 count of krits in the category.

It will if I remove the WHERE statement but I need the WHERE to only select the krits where the field approved = 1

© Stack Overflow or respective owner

Related posts about mysql