Reputation: 22605
I wrote a question a few hours ago about many to many queries. mellamokb suggested:
How about list the categories, and how many posts in each category, sorted from the category with the most posts to the category with the least.
How do I actually make the query string? I can't even think where to start.
Upvotes: 0
Views: 49
Reputation: 6683
SO... Is this the sort of thing that you are looking for?
SELECT category.name
, COUNT(*) as [Count]
FROM post
INNER JOIN postcategory ON post.id = postcategory.post_id
INNER JOIN category ON postcategory.category_id = category.id
ORDER BY count
GROUP BY category.name
Upvotes: 1