I working on a tag based search. I have three tables tag(id,name), tagXmedia(id,tag_id,media_id), and media(id,...). tagXmedia is the mapping table between the tag and media
SELECT
T1.media_id
FROM
tagXmedia as T1
INNER JOIN media as T2
ON T1.media_id =T2.id
INNER JOIN tag as T3
ON T1.id = T3.tag_id AND T3.name IN ('home','hawaii')
GROUP BY T1.media_id