I have a media table and a tag_media table. The tag_media table is a relationship table that contains the columns id_tag and id_media. A single media file can be tagged with multiple tags. Something like:
tag_media:
id_tag
id_media
media:
id_media
(etc, etc)
I need a query that will allow me to fetch all media that was tagged with a set of mandatory tags and a set of optional tags so that I can guarantee that the returned media were tagged with ALL the mandatory tags and AT LEAST one of the optional tags.
How can I do this?
This assumes that one media item cannot have duplicate tags.