1) Your term_node table is missing a PK. Maybe you're having duplicate entries in there? That could explain the high numbers.
2) Putting a WHERE condition (different from IS [NOT] NULL) on a left joined table makes it behave as an INNER JOIN. Put those conditions in the ON.
3) Counting with left join has a problem: even if there aren't any nodes with status 1 for a particular term, your query would still give 1 as a result, because there would be one row returned for that term, even if the node columns would be NULL.
Try with a subquery like this:
Code:
SELECT
td.name AS 'Community',
COALESCE(Count, 0) AS Count
FROM term_data td
LEFT JOIN
(SELECT tn.tid, COUNT(*) AS Count
FROM term_node tn
INNER JOIN node n
ON tn.nid = n.nid
WHERE n.status = 1
GROUP BY tn.tid
) AS a
ON a.tid = td.tid
WHERE td.vid = 31
ORDER BY Count DESC
Bookmarks