I have 2 tables:
- posts
- tags
Tags table is structured like this:
- post_id
- tag
So for every tag that's given for a post, I create a record in the tags table. If a post has 10 tags, there will be 10 records in tags table with that post_id.
I'm now trying to build a search page where users can do a search for posts where tags do not contain the given keywords. This creates a problem though. A query like:
SELECT DISTINCT posts.id, posts.title, posts.content
FROM jobs, tags
WHERE tags.tag NOT LIKE '%$keywords%' AND posts.id=tags.post_id
doesn't work because if a post has got 6 tags and one of them has got the keyword, it will still be returned because the other 5 records in the tags table don't have that keyword.
What's the best way to solve this? Any way other than creating a new column in the posts table which stores all the comma-separated tags used only for search??