Here's what I need to fetch:
- posts that have comments
- number of comments per post
- number of unread comments per post (expressed by a bool "read" column in the "comments" table)
The last part is what I'm having trouble with.
Here's my SQL so far:
SELECT
posts.id
, posts.title
, COUNT(comments.id) AS commentsCount
FROM posts
INNER JOIN comments
ON comments.postID = posts.id
GROUP BY
posts.id
ORDER BY
comments.createDate DESC
This works fine so far, but I need to COUNT() how many comments have their "read" field equal to 0. I'm not sure how to perform this additional COUNT() within the existing query.
Thanks in advance!