I've got a query that counts the number of posts in a month with a certain tag, but obviously my WHERE won't return anything if there are no posts. The problem with that, I have overlayed on the chart another query that shows ALL posts, not just the ones who meet these WHERE conditions. The second query will typically have a result for every month. How can I get this query to return zero if the result is null? I've read a few of the answers here, but can't quite figure it out.
SELECT MONTHNAME(post_time) AS month,
COALESCE(Count(distinct p.post_id), 0) AS count
FROM post.p
INNER JOIN post_tag_map t ON ( p.post_id = t.knote_id )
WHERE t.post_id IN (23,24,49,54)
/*these numbers are actually a variable, this is just an example*/
AND p.post_time >= (CURDATE() - INTERVAL 1 YEAR)
I'm trying to show both Months and Posts from the beginning of time of the database.