You're missing a limit clause in the inner query which would return the tag_id with the maximum count. As it is, it would return all the tag_ids, albeit in order. Consequently, the outer query would also select all the tags, which worked in our one tag table, but wouldn't with a table with more than one tag.