Thanks for taking the time to help:
I have a table of media each with a unique ID.
I have a table of tags, each with a unique ID.
I have a table that matches the tags to the media:
So, in this example, hitler.gif is confusing and sad. Cat.jpg is just funny.
This table that associates tags with media will end up being HUGE. I don't mind it being huge, but I do need to be extra efficient when I work with it to keep CPU load down. I need an efficient way to find photos with very specific attributes. For example, I might need to find all photos that are both Funny (tag 20) AND Confusing (tag 22) but that are not also tagged as offensive (tag 25) OR NSFW (tag 30).
I'm an SQL newbie, so I'm used to "SELECT x from y where Tag = 22 as a generic simple call to find specific data. But I can't just say where tag = 22 AND tag = 24. No ands will ever return a result because each association between tag and image is a separate row. No row tests true for two attributes. So, how do I do comparisons on multi-row data? Specifically, how do I do comparisons on multi-row data that combines looking for media with certain tags, specifically without certain tags, potentially with "ands", and potentially with "ors". Hopefully that makes sense. I'm trying to avoid doing this logic part with PHP, if possible.
Sorry if the answer is obvious. I tried to google for this, and couldn't find anything because I wasn't quite sure what keywords to search for.
Thank you, thank you, thank you for the help.
I have a table of media each with a unique ID.
Code:
**********************
* ID * Filename *
**********************
* 56 * Cat.jpg *
* 57 * Dog.jpg *
* 58 * Hitler.gif *
**********************
I have a table of tags, each with a unique ID.
Code:
**********************
* ID * Attribute *
**********************
* 20 * Funny *
* 21 * Sad *
* 22 * Confusing *
**********************
I have a table that matches the tags to the media:
Code:
*********************
* Media ID * Tag ID *
*********************
* 58 * 22 *
* 58 * 21 *
* 56 * 20 *
*********************
So, in this example, hitler.gif is confusing and sad. Cat.jpg is just funny.
This table that associates tags with media will end up being HUGE. I don't mind it being huge, but I do need to be extra efficient when I work with it to keep CPU load down. I need an efficient way to find photos with very specific attributes. For example, I might need to find all photos that are both Funny (tag 20) AND Confusing (tag 22) but that are not also tagged as offensive (tag 25) OR NSFW (tag 30).
I'm an SQL newbie, so I'm used to "SELECT x from y where Tag = 22 as a generic simple call to find specific data. But I can't just say where tag = 22 AND tag = 24. No ands will ever return a result because each association between tag and image is a separate row. No row tests true for two attributes. So, how do I do comparisons on multi-row data? Specifically, how do I do comparisons on multi-row data that combines looking for media with certain tags, specifically without certain tags, potentially with "ands", and potentially with "ors". Hopefully that makes sense. I'm trying to avoid doing this logic part with PHP, if possible.
Sorry if the answer is obvious. I tried to google for this, and couldn't find anything because I wasn't quite sure what keywords to search for.
Thank you, thank you, thank you for the help.