I have this table tagMusic
id tagid musicid
---------------------
1 1 141
2 4 141
3 3 102
So I need to say: take me all the music ID who have tag Id 1 AND 4 (for example ).
I have this table tagMusic
id tagid musicid
---------------------
1 1 141
2 4 141
3 3 102
So I need to say: take me all the music ID who have tag Id 1 AND 4 (for example ).
One way about it is to select only those tags and count how many unique results you got per tag:
SELECT musicid
FROM tagmusic
WHERE tagid IN (1, 4)
GROUP BY musicid
HAVING COUNT(*) = 2