I have two tables that are related, which, for the purpose of this question, will be called posts and tags. posts contains various postings, such as those found on a community forum system. tags contains a unique set of tags, that are added when the server encounters a new tag that is not already in the system. There is only one entry per tag.
posts can have multiple tags, and tags can have more than one post that is a reference to it. To handle these references back and forth, I have created a table to sit in between these two tables, called posttags. posttags contains a reference to the tag id and the post id. This is how the many to many relationship is maintained.
Now, on to the problem. I need to be able to select posts based on a tag. This is a simple join when there is only one tag to search for, but I am at a loss as to how to handle multiple tags. For instance, I need to be able to search the database and get results that have ALL of the tags that are in a list (e.g., "php, mysql, sql"), without using SQL inside of a loop or any other low performance options.
I am not sure how to do this. Can anyone point me in the correct direction?
Thanks!