I have a many to many table that holds both EventId and TagId.
+-------+---------+
| TagId | EventId |
+-------+---------+
| 150 | 61096 |
| 149 | 61096 |
| 149 | 61095 |
+-------+---------+
How can I query for only EventId’s that match both TagId 149 and TagId 150?
Desired result:
+---------+
| EventId |
+---------+
| 61096 |
+---------+
3
Answers
This works for finding the events that have only these two tags:
This works for finding the events that have at least these two tags:
This can be done using :
Or simply :
Demo here
If
(EventId, TagId)
is unique then DISTINCT not needed.