Maybe something like:
SELECT img_ID FROM tagMap t1
WHERE tag_ID = 51
AND exists (select 1 from tagmap t2 where t2.tag_ID = 52 and t2.img_ID = t1.img_ID)
Edit: Another option is
select t1.img_ID
from (SELECT * FROM tagMap WHERE tag_ID = 51) t1
inner join (SELECT * FROM tagMap WHERE tag_ID = 52) t2 ON t1.img_id = t2.img_ID
Depending on the number of tags you want to select for and the data volumes one or the other might be easier/faster. For large data volumes in the tables and large numbers of tags to select for, neither are likely to scale well (for each additional tag you want to include as a condition you need an additional sub select in both cases)
Addition:
Another possible solution:
SELECT Q.img_id FROM (
SELECT img_ID, count(1) as num
FROM tagMap t1
WHERE tag_ID in (51, 52)
GROUP BY img_id ) Q
WHERE Q.num = 2
I think this one might well scale best. To add extra tags simply add to the in()
condition and increase the number matched by the outer where condition. E.g.
SELECT Q.img_id FROM (
SELECT img_ID, count(1) as num
FROM tagMap t1
WHERE tag_ID in (51, 52, 59)
GROUP BY img_id ) Q
WHERE Q.num = 3