I am writing a web application similar to a blogging software. There are three tables as below
Posts Table: Post_id,Post_Text Post_Tags Table: Post_id,Tag_i
This is relational division.
Use GROUP BY and COUNT or double NOT EXISTS.
GROUP BY
COUNT
NOT EXISTS
An example of the first approach would be.
SELECT pt.Post_id, p.Post_Text FROM Post_Tags pt JOIN Posts p ON p.Post_id = pt.Post_id WHERE pt.Tag_id IN (1,2,3) GROUP BY pt.Post_id HAVING COUNT(DISTINCT pt.Tag_id) = 3