Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:26:52+00:00 2026-06-05T17:26:52+00:00

okay, i’m setting up a multi-user chat system. i have a messages table, that

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:26:54+00:00Added an answer on June 5, 2026 at 5:26 pm
    SELECT  mt.id
    FROM    (
            SELECT  list_id
            FROM    participantlist_links pll
            WHERE   participant_id IN (1, 2)
            GROUP BY
                    list_id
            HAVING  COUNT(*) = 2
            ) q
    JOIN    message_threads mt
    ON      mt.participantlist_id = q.list_id
    WHERE   NOT EXISTS
            (
            SELECT  NULL
            FROM    participantlist_links pll
            WHERE   pll.list_id = q.list_id
                    AND pll.participant_id NOT IN (1, 2)
            )
    

    Create the following indexes:

    participantlist_links (participant_id, list_id) -- unique
    participantlist_links (list_id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so what I have is a table that keeps track of history on
Okay so here is what I'm trying to accomplish. First of all below table
Okay, basically I've developed a simple image upload system. The user selects a local
Okay, I have hundreds of .net controls with text attributes that needs to be
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay i have a HTML TABLE , with 4 TDs in a TR(tow) as
Okay I have a csv file that gets parsed and displayed. I want to
Okay, I've set up a bit of code which searching for all the pages
Okay, so I have the weirdest problem right now. My code is fine! It
Okay, none of the previous questions I have seen with this error seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.