I have the following table, witch is the relationship pivot table, between posts and tags:
I need to get the posts that strict contain a 'X' given tag(s).
For example:
If I need posts with exclusively tags 1 and 2, it should returns post_id 1 and 4.
If I need post with tag 2, it should only returns post_id 3.
If I need post with tag 23, it should't returns nothing.
I've tried with:
SELECT * FROM `post_tags` WHERE tag_id = 1 OR tag_id = 2;
but obviously it returns all post_id with these tags_id
And with:
SELECT * FROM `post_tags` WHERE tag_id = 1 AND tag_id = 2;
It doest's return anything, because it's trying to comparate between columns.
Any solution?