data scheme is as follows
Create table post (id, name) Create table post_to_tag (post_id, tag_id) Create table tag (id, name) It is necessary to write a query that extracts all objects A (posts) to which objects B (tags) are attached with the values 'tag1' and 'tag2' (at the same time, the intersection is important). But at the same time from the sample you need to remove posts that have tags with the values of the name 'tag3' and 'tag4'
The intersection of the tags present is extracted like this:
SELECT p.id, GROUP_CONCAT(DISTINCT all_tags.name) as i_tag from post as p INNER JOIN post_to_tag AS ptg1 ON ptg.post_id = p.id INNER JOIN tag AS t1 ON ptg1.tag_id = t1.id and t1.name = 'тэг1' INNER JOIN post_to_tag AS ptg2 ON ptg.post_id = p.id INNER JOIN tag AS t1 ON ptg2.tag_id = t2.id and t2.name = 'тэг2' INNER JOIN post_to_tag AS all_ptg ON all_ptg.post_id = p.id INNER JOIN tag AS all_tags ON all_git.tag_id = all_tags.id GROUP BY (i.id) Tell me, how can you filter by missing ???