Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:27:40+00:00 2026-05-14T03:27:40+00:00

My problem is that I’m trying to count which tag has been used most

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:27:40+00:00Added an answer on May 14, 2026 at 3:27 am

    You should make 2-3 tables. I usually make 3:

    code

    • id
    • code

    code_tags:

    • code_id
    • tag_id

    tags:

    • id
    • name

    To make a query which shows the amount of tags used:

       SELECT t.*, COUNT(tag_id) as code_count 
         FROM code_tags ct 
    LEFT JOIN tags t ON ct.tag_id = t.id 
     GROUP BY tag_id 
     ORDER BY code_count DESC 
        LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been a problem that I haven't been able to figure out for
I just have a problem that I have been trying to fix for the
This has been a problem that has existed on 3 projects for me. I
The problem that I am having has to do with the need to keep
I am having the problem that I cannot select a specific XML node which
He're an interesting problem that looks for the most Pythonic solution. Suppose I have
A problem that has frequently come up in my career is I have some
I'm facing a problem that Google couldn't solve yet! I'm trying to store URLs
I have a problem that I can't seem to solve. What I am trying
I am having this problem that I had used Arraylist in my entire program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.