开发者

Select most popular tags from database?

开发者 https://www.devze.com 2022-12-13 21:18 出处:网络
I have two tables linked togeth开发者_如何学运维er through the 3rd table threads: id, name tags: id, name

I have two tables linked togeth开发者_如何学运维er through the 3rd table

threads: id, name
tags: id, name
thread_tag_map: threads_id, tags_id

Its a many to many relationship. I want to select 30 tags that are most popular that is to say the first 30 tags with tags_id which occur the most in thread_tag_map.


SELECT
  t.*
FROM
  tags t
JOIN
  thread_tag_map ttm ON t.id = ttm.tags_id
GROUP BY
  t.id
ORDER BY
  COUNT(t.id) DESC
LIMIT 30
0

精彩评论

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