views:

61

answers:

1

i have 2 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.

i think you understand my question (and sorry for my bad english...im not from the states. maybe someone could change my words to more correct ones=))

+5  A: 

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

hsz
thx a lot dude!!
never_had_a_name