开发者

Many-to many query

开发者 https://www.devze.com 2023-02-14 18:01 出处:网络
given a relation like this: Posts ||Taggins ||Tags| |------|---------------- id||id|| 开发者_如何转开发id |

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
0

精彩评论

暂无评论...
验证码 换一张
取 消