Mysql - find conversation only being held by two users

前端 未结 2 1221
名媛妹妹
名媛妹妹 2021-01-14 20:21

I have a table called participants with the following fields:

  • id
  • user_id
  • conversation_id

The background is that there ar

2条回答
  •  庸人自扰
    2021-01-14 20:30

    select conversation_id
    from participants
    where user_id in (1,2)
    group by conversation_id
    having count(user_id) = 2
    

    Return two users conversation_id

提交回复
热议问题