에 많은에서 SQL I 다음 스키마했습니다 :많은 관계
Users
-----
id
name
Conversations
-------------
id
other
Partecipants (join table)
------------
id
user_id
conversation_id
other
사용자가 많은 대화를 가질 수 있고 대화가 많은 사용자에 속해 있습니다.
다른 사용자의 하위 집합과 함께 모든 대화를 선택해야합니다.
내 시도는 (작동하지 않습니다)입니다 :
SELECT *
FROM `conversations`
INNER JOIN `participants` ON `conversations`.`id` = `participants`.`conversation_id`
WHERE `participants`.`user_id` = 1
AND (participants.user_id IN (4,6))
GROUP BY participants.conversation_id
어떤 생각을?
하나의 'Participants' 행에 대한 사용자 ID가 둘 다 1과 4 또는 6 중 하나 일 수 있습니까? 그건 말이 안돼. – Bridge