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
You should make 2-3 tables. I usually make 3:
code
code_tags:
tags:
To make a query which shows the amount of tags used: