所以,我有一个实体(我使用的是symfony)Participant
。
在这个实体中,我有:id
account_id
conversation_id
account_id
是User
对象,conversation_id
是Conversation
对象,两者都是外键。
首先,我需要知道user1和user2是否在同一个对话中。然后我需要知道user1、user2……userN是否在同一个对话中。
我不知道如何简单地通过查询来做到这一点?谢谢
SELECT
n.*
FROM
Participant n JOIN
(
SELECT
t.conversation_id
FROM
Participant t
WHERE
t.user_id = 'user1'
AND
t.conversation_id = (SELECT conversation_id FROM Participant WHERE user_id = 'user2' AND conversation_id = t.conversation_id)
) m on m.conversation_id = n.conversation_id