okay, i’m setting up a multi-user chat system.
i have a messages table, that holds all the messages – simplified:
messages:
id,
content,
thread_id
then i have a threads table:
messages_threads:
id,
participantlist_id
then i have a participantlist table:
participantlist:
list_id,
name
and i have a participantlist_links table:
participantlist_links:
list_id,
participant_id
now i’d like to find out the thread id from a list (array) of participants, i came up with this:
$threadid_sqlquery = "
SELECT messages_threads.id FROM messages_threads
JOIN participantlist_links
ON messages_threads.participantlist_id = participantlist_links.list_id";
foreach($participants_array as &$participant_id){
$maxid_sqlquery .= "
AND participantlist_links.participant_id='".$participant_id."'";
}
but now: i’m looking for the thread_id of a chat between users 1 and 2 – there is a multi-user chat with users 1,2,3 and a chat with users 1,2,3,4 i get a result of three rows, but i only want the one where only users 1 and 2 are participants.
is there any way to query for that?
Create the following indexes: