Can someone help with a query, please?
I have a table of projects. And a table of images that point to their parent project, and then a table of image_tag (search words associated with the images) that each point to the parent image. Each image can have multiple tags associated with it. Each image can have only one owning project, and projects have multiple images.
Here are the tables:
Project ( id, visible )
Image ( id, project (owning project id), [other stuff] )
Image_tag ( id, image (owning image id), search_term )
I want to query the db for images that have more than one tag (for instance, images that are tagged both as 'animals' and 'landscape'). So, there would be two image_tag recs for such an image, both pointing to the same image, one with search_term= 'animals' and one with search_term= 'landscape'. Ultimately, I'd like to also be able to get only images that belong to projects that have 'visible'='1'.
I can get it all to work for matching just one image_tag, but can't see how to do this with multiple image_tag recs. Maybe I need to look for each tag than join the results?
So, if someone could help with either the query, or just how to go about thinking about this, I'd so appreciate it.