0
我有以下模式:SQL選擇多對多的關係
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'行的用戶標識如何等於1和4或6?這沒有任何意義 – Bridge