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 7725107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:51:22+00:00 2026-06-01T04:51:22+00:00

I have a simple message schema where a thread ties 2 or more users

  • 0

I have a simple message schema where a “thread” ties 2 or more users to a stream of messages. Each message belongs to a single thread. It works just like SMS messages, or Facebook messages.

Given a string (representing a name or partial name of a user), I need a query that will find all threads that match where:

  1. the current user (userID) is a member of the thread
  2. the name or partial name of a user is also a member of the thread

Here are my tables:

MessageThreads:
threadID
lastUpdated

MessageThreadUsers:
threadFK
userFK

Users
userID
userFirstName
userLastName
userFullName

This query gets all threads that the current user belongs to:

SELECT DISTINCT threadFK FROM MessageThreadUsers
WHERE userFK = 'usr_developer'

But how would I join each thread with all users in the thread (not including the current user) that match by name or partial name?

  • 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-01T04:51:23+00:00Added an answer on June 1, 2026 at 4:51 am

    This should show you the other users of all threads that the ‘usr_developer’ key is part of.

        SELECT MT.ThreadId, U.userID, U.userFullName
          FROM MessageThreads MT 
    
    INNER JOIN MessageThreadUsers MTCU on (MTCU.threadFK = MT.threadID)
    INNER JOIN Users CU on (MTCU.userFK = CU.userID and CU.userID = 'usr_developer')
    
    INNER JOIN MessageThreadUsers MTU on (MTU.threadFK = MT.threadID)
    INNER JOIN Users U on (MTU.userFK = U.userID and U.userID <> 'usr_developer') 
    
         WHERE U.UserFullName like '%John%' -- Do your filters here
    

    This joins against the tables twice, first, we join to the users table to only pull back the set of threads that have a user with the id of ‘usr_developer’. Then we join the resulting threads against the users table again, this time where the user id is not usr_developer. Finally we can filter the result set by the name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple message schema where a thread ties 2 or more users
I have a simple messaging schema where each message has a senderFK and a
I have a single AMQ queue that receives simple messages with string body. Consider
I have written a simple WCF service that accepts and stores messages. It works
I'm designing a simple messaging schema where a thread groups all messages that are
I have a simple message box in a WPF application that is launched as
I have a simple Message table, with 2 indexes: mysql> show keys from Message;
I have a simple GtkStatusBar created with glade,and want to add a simple message
I have a simple contact form with Subject and Message that I want to
I have a simple doc.xml file which contains a single root element with a

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.