我想让查询获取两个用户之间的聊天id,我已经有了这两个用户id,但不知道怎么做。有很多聊天id与每个用户id存储,但我只需要获取2个记录,其中具有相同的聊天id和2个不同的用户id,我将提供query.Thanks读取和帮助……
+-------+-------+
|chat-id|user-id|
+-------+-------+
|1 |1 |
+-------+-------+
|1 |2 |
+-------+-------+
|2 |1 |
+-------+-------+
|2 |3 |
+-------+-------+
|3 |2 |
+-------+-------+
|3 |3 |
+-------+-------+
|4 |1 |
+-------+-------+
|4 |4 |
+-------+-------+发布于 2019-05-10 18:28:17
如果您希望在两个特定用户之间进行聊天:
select chat_id
from t
where user_id in (@id1, @id2)
group by chat_id
having count(*) = 2;这假设该表没有重复项。如果可以,则使用count(distinct user_id) = 2。
https://stackoverflow.com/questions/56075525
复制相似问题