How to check the different rows of the same value?

0 like 0 dislike
7 views
There is a table to link posts and tags
5ae4e428eb5d5938470138.png
And I need to get valid post_id which has tag_id 2 and 8.
I can find record with tag_id 2, save the post_id and look at this more post_id and tag_id 8, but tags can be 5 and it will be 100500 queries.
Or maybe you have other ideas for implementations communication of tags with the posts and search for them?
by | 7 views

3 Answers

0 like 0 dislike
SELECT post_id
FROM Tags
WHERE tag_id IN (1,2 ,5 , 10, 100)

\rwww.dofactory.com/sql/where-in
by
0 like 0 dislike
SELECT DISTINCT post_id FROM table_name WHERE tag_id IN (2, 8, 100500);
by
0 like 0 dislike
HAVING sum(1) = &total_tag_coung
by

Related questions

0 like 0 dislike
2 answers
asked Apr 1, 2019 by gibigate
0 like 0 dislike
2 answers
asked Apr 1, 2019 by gibigate
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
33,895 users