Many-to many query
given a relation like this:
|Posts | |Taggins | |Tags|
|------| ---------- ------
| id | | id | | 开发者_如何转开发id |
| post_id|
| tag_id |
I want to find 5 tags with the biggest amount of posts.
I am quite confused how I should approach it with joins and count, as I can't get anything right so far.
Something like this?
SELECT TOP 5 tag_id, count(*) cnt
FROM Taggins
GROUP BY tag_id
ORDER BY cnt DESC
精彩评论