I have two tables linked together 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With