I've got the following table:
nid | tag_id
--------------
1 | 213
1 | 78
2 | 938
2 | 1002
2 | 8573
2 | 5
3 | 3957
3 | 487
4 | 56
I want to retreive a single nid where tag_id matches several values say 1002,938,8573.
I started with the following query:
SELECT nid,GROUP_CONCAT(DISTINCT tag_id ORDER BY tag_id) tag_ids FROM table GROUP BY nid
which returns:
nid | tag_ids
--------------
1 | 78,213
2 | 5,938,1002,8573
3 | 487,3957
4 | 56
But I haven't found anything yet that'll will allow me to match the tag_ids column again my set of values. I need it to match all not just anyone of the values.
Maybe my approach is wrong so happy to look at different methods.