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 8064787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:28:37+00:00 2026-06-05T11:28:37+00:00

Once again a question about mysql with my small database to practise with: I

  • 0

Once again a question about mysql with my small database to practise with:

I got the tables as followed:

Songs       Link        Tags
=======     =====       =======
Sid          Sid        Tid
Songname     Tid        Tagname

Now what I am trying to do is once i query (or search for) a song with entering some tags, to display how many tags that song has to create a match percentage.

Thanks to the awesome stackoverflow community i got the query

SELECT s.Sid, s.Songname
FROM Songs s
JOIN Link l ON ( l.Sid = s.Sid )
JOIN Tags t ON ( t.Tid = s.Tid )
WHERE t.Tagname IN ( 'X', 'Y' )
GROUP BY s.Sid, s.Songname
HAVING COUNT(1) = 2

Which searches for songs that match exactly these 2 tags.
Suppose now you’ve got this song A which has tag G, X, Y, and Z.
The query finds this song because it has X and Y in it.
However the song got 2 others, thus I want to create (with php) a match % showing 50% for this one.

I don’t have any trouble with the php part, but i cant figure out a query to get all songs that match these tags along with their total amount of tags in one result set.

Cheers!

Edit1:


I noticed that most of the answers show what I’ve already tried. So i’ll make another more deep example:
Suppose you’ve got the following 4 songs:

A with tags A, B, X and Y
B with tags A, B, C, D, E, X, Y
C with tags A, B, C, D, F, X
D with tags X and Y

Now the query for searching songs with tags X and Y is enterred. I want the following output:

TotalNumberOfTags:    Song:
4                      A
7                      B
2                      D

C didn’t have X AND Y so he falls out.

Edit2:


To illustrate i want to use the query

SELECT COUNT(t.Tagname) FROM FROM Songs s 
JOIN Link l ON ( l.Sid = s.Sid ) 
JOIN Tags t ON ( t.Tid = s.Tid ) 
WHERE s.Songname="A"

on the whole returning set of songnames caused by the queries above, in one query to use ORDER BY COUNT(t.Tagname) ASC on the set.

  • 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-06-05T11:28:38+00:00Added an answer on June 5, 2026 at 11:28 am

    The answer i found is a work around but it works.
    I create a temporary table like this

    CREATE TEMPORARY TABLE numberoftags ( songname VARCHAR(50) NOT NULL, numberoftags INT);
    

    which i fill with the 2 separate queries i displayed in my question.
    Then with with a simple query

    SELECT * FROM numberoftags ORDER BY numberoftags DESC
    

    I receive all songs with their total number of tags, which i display one by one.
    After i close the connection in php this temporary table automatically get’s removed, so no hassling about that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once again a question about the garbage collector in actionscript-3: If I have a
Once again a question about extjs. I use EXT 4.0.2 and have a couple
Once again I have a question about Eclipselink/MOXy with external metadata mapping file. I
Good day, friends. Once again stupid question about Obj-C from newbie :) I'm trying
Once again I've searched for about 45 minutes for an answer to this question
once again I've got a question. Since I am using Google Web Toolkit (GWT)
Hell once again, I am wondering how do you go about adding data to
I've got a very simple question about a game I created (this is not
I've got a question about treating references to jQuery objects. Let suppose in my
me again. Sorry about this. Following on from my previous question (I think I

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.