Note that there are some explanatory texts on larger screens.

plurals
  1. POSubquery returns multiple rows issue
    primarykey
    data
    text
    <p>Once again a question about mysql with my small database to practise with:</p> <p>I got the tables as followed:</p> <pre><code>Songs Link Tags ======= ===== ======= Sid Sid Tid Songname Tid Tagname </code></pre> <p>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.</p> <p>Thanks to the awesome stackoverflow community i got the query</p> <pre><code>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 </code></pre> <p>Which searches for songs that match exactly these 2 tags. <br/> Suppose now you've got this song A which has tag G, X, Y, and Z. <br/> 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.<br/><br/> 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.</p> <p>Cheers!</p> <h2>Edit1:</h2> <p><hr/> I noticed that most of the answers show what I've already tried. So i'll make another more deep example: <br/> Suppose you've got the following 4 songs: <br/><br/> A with tags A, B, X and Y <br/> B with tags A, B, C, D, E, X, Y <br/> C with tags A, B, C, D, F, X <br/> D with tags X and Y <br/><br/></p> <p>Now the query for searching songs with tags X and Y is enterred. I want the following output: <br/></p> <pre><code>TotalNumberOfTags: Song: 4 A 7 B 2 D </code></pre> <p>C didn't have X AND Y so he falls out.</p> <h2>Edit2:</h2> <p><hr/> To illustrate i want to use the query</p> <pre><code>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" </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload