Counting the most tagged tag with MySQL

Posted by Jack W-H on Stack Overflow See other posts from Stack Overflow or by Jack W-H
Published on 2010-04-03T16:37:30Z Indexed on 2010/04/03 16:43 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

Hi folks

My problem is that I'm trying to count which tag has been used most in a table of user-submitted code. But the problem is with the database structure.

The current query I'm using is this:

SELECT tag1, COUNT(tag1) AS counttag 
FROM code 
GROUP BY tag1 
ORDER BY counttag DESC LIMIT 1

This is fine, except, it only counts the most often occurence of tag1 - and my database has 5 tags per post - so there's columns tag1, tag2, tag3, tag4, tag5. How do I get the highest occurring tag value from all 5 columns in one query?

Jack

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query