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
精彩评论