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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:18:24+00:00 2026-05-31T14:18:24+00:00

I have a simple messaging schema where each message has a senderFK and a

  • 0

I have a simple messaging schema where each message has a senderFK and a recipientFK, each mapping to a user record. For the current user, I need to get all distinct threads. A distinct thread is the either the senderFK or the recipientFK for the user who has either sent or received a message.

So, for example:

This query gets all users who sent a message to the current user:

SELECT DISTINCT senderFK AS threadID FROM Messages
WHERE recipientFK = 'usr_developer'

This query gets all users who have received a message from the current user:

SELECT DISTINCT recipientFK AS threadID FROM Messages
WHERE senderFK = 'usr_developer'

How would I combine these queries into a single table that has a distinct row for each user and a single column (threadID)?

  • 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-05-31T14:18:25+00:00Added an answer on May 31, 2026 at 2:18 pm

    Something like this should work:

    SELECT recipientFK as UserId, senderFK as ThreadID
     FROM Messages
    UNION
    SELECT senderFK as UserID, recipientFK AS threadID
     FROM Messages
    

    This method leaves out user filters based on your comment ...a distinct row for each user ...

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

Sidebar

Related Questions

I have a simple messaging system in Rails with a Message table for the
I have a simple messaging system, and I'd like to display both Received and
i have a string like this: some_string=A simple demo of SMS text messaging. +
I have a simple messaging queue setup and running using the Zend_Queue object heirarchy.
I'm creating a simple messaging app, in which the user can send either an
I have quite a simple question I think, but I need a definitive answer.
I have a simple messaging system on my site. I would like to implement
I have built a very simple internal messaging system inside my application, i want
I have written a simple messaging system for a CMS I am developing and
I have a simple messaging system that up till now uses file based storage.

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.