this is my conversation table:
conversationID || userID
1 || 1
1 || 2
2 || 1
2 || 2
2 || 3
as you can see each conversation can contain 2 users or more.
I am trying to get the id of the conversation that only 2 users are there.
ie conversation that contains only users 1 & 2, the answer is conversation 1.
but how do I get it?
This will select all conversations that have users 1 or user 2, or both, but no one else:
If you also want all conversations that have exactly user 1 and 2, and no one else, you also have to add an and condition:
If userID can be duplicated, it’s also better to use distinct: