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

  • Home
  • SEARCH
  • 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 526783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:48:48+00:00 2026-05-13T08:48:48+00:00

I have a MySQL database with various tables whose records can be tagged, so

  • 0

I have a MySQL database with various tables whose records can be tagged, so I have a tags table, and a tag_associations table that relates tags to other “taggable” tables via multiple foreign keys, and also to an “owning” user — my fields are something like the following:

  • tag_association_id (primary key)
  • user_id (tag association creator)
  • tag_id (related tag)
  • artist_id (tagged artist, can be null)
  • album_id (tagged album, can be null)
  • track_id (tagged track, can be null)

I basically want to count all items that have been tagged a particular tag — so something along the results of this query:

SELECT
    COUNT(ta.tag_association_id) AS how_many
FROM
    tag_associations AS ta
    LEFT JOIN users AS u ON ta.user_id = u.user_id
WHERE
    ta.tag_id = '480'
    AND u.user_status = 'active'

But the problem with this query lies in cases where the same tag has been applied to the same item by multiple users, so if 2 different users tag the artist ‘Bobby Jones Band’ as ‘rad’, it counts both of the tag associations where I just want to count it once. I tried adding this to the above:

GROUP BY ta.artist_id, ta.album_id, ta.track_id

…which got me close, but didn’t yield the exact results I needed — it gave me multiple row results of different counts. Is there any magic I can use in a case like this and keep it in a single query? While remaining as efficient as possible, of course 🙂 Thanks!

  • 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-13T08:48:48+00:00Added an answer on May 13, 2026 at 8:48 am

    If I got your question right, then your GROUP BY should almost do the job.

    This solution should get the unique rows from tag_associations and count them.

    SELECT COUNT(*)
    FROM
    (
        SELECT 1
        FROM tag_associations AS ta 
        LEFT JOIN users AS u ON ta.user_id = u.user_id
        WHERE ta.tag_id = '480' 
        AND u.user_status = 'active' 
        GROUP BY ta.artist_id, ta.album_id, ta.track_id
    ) x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 345k
  • Answers 345k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just use GL_TRIANGLE_STRIP, there will be four strips per segment… May 14, 2026 at 5:49 am
  • Editorial Team
    Editorial Team added an answer Try var origin = document.getElementById('origin_select'); var target = document.getElementById('target_select'); //… May 14, 2026 at 5:49 am
  • Editorial Team
    Editorial Team added an answer Project files are xml, so there is no reason why… May 14, 2026 at 5:49 am

Related Questions

I have an embarrassing question regarding Access. I can build relational databases in my
I'm familiar with a whole bunch of ways to authenticate users for the web-based
This is a separate question, but it is related to an earlier question: Three
Here's the basics of the system we have in place today. We have a
Trying to use Linq to SQL for a small project I'm working on at

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.