Query to get termID, term name and number of posts that has that term I can figure out how to construct a db query that fetches term id and term name. But how do I associate a count of nid's that has this term? I'm looking to do this programatically through the DB api.

Any help would be greatly appreciated, as I'm running low on time.
See the example for Views Group By -- "List top 10 most frequent terms applied to a specific node type and the number of nodes for each term."