これにより、ユーザー 1 またはユーザー 2、またはその両方が含まれ、他のユーザーが含まれていないすべての会話が選択されます。
select conversationID
from conversations
group by conversationID
having count(*) = count(case when userID in (1,2) then 1 end)
ユーザー 1 と 2 だけが含まれ、他のユーザーがいないすべての会話も必要な場合は、and 条件も追加する必要があります。
select conversationID
from conversations
group by conversationID
having count(*) = count(case when userID in (1,2) then 1 end)
and count(*) = 2 -- number of elements in set
userID を複製できる場合は、distinct を使用することもお勧めします。
select conversationID
from conversations
group by conversationID
having
count(distinct userID) = count(distinct case when userID in (1,2) then userID end)
and count(distinct userID) = 2 -- number of elements in set