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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:39:50+00:00 2026-05-25T03:39:50+00:00

For a messages table with the following structure id, sender_id, receiver_id, text I want

  • 0

For a messages table with the following structure

id, sender_id, receiver_id, text

I want to build a list of distinct users (ordered by message id) who have either sent a message to or received one from the current session holder. The list should contain a user only once.

A query such as:

"SELECT * FROM messages WHERE sender_id = '$sess_id' OR receiver_id = '$sess_id'";

yields duplicates i.e. multiple rows with the same user. Does one necessarily have to do the filtering after the SQL query or is there an SQL query that will yield the desired unique list?

Thanks!

  • 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-25T03:39:51+00:00Added an answer on May 25, 2026 at 3:39 am

    You could do:

    SELECT sender_id
    FROM   messages
    WHERE  receiver_id = '$sess_id'
    UNION
    SELECT receiver_id
    FROM   messages
    WHERE  sender_id = '$sess_id'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: messages - with following structure id sender_id receiver_id message_text users
I have the following table structure. I want to select distinct CustomerId and CustomerName
I've got a database table called 'mesg' with the following structure: receiver_id | sender_id
Consider the following messages table: _date message ------------------------- 2012-02-22 hello 2012-02-22 another msg! 2012-03-05
I have a simple table maintaining messages between users. The table structure looks like
Consider the following database tables: Table messages with 13,000,000 rows (one row per message).
I have a discussion board with the following table structure: +-------------------------------+ | TABLE: MESSAGES
Not the best title, I apologise. Table structure: messages id - int message -
I have the following table structure: <tr> <th><label for=ctl00_bodyContent_username>username:</label></th> <td class=field><input name=ctl00$bodyContent$username type=text id=ctl00_bodyContent_username
What is the best table structure to store dialogs between users in private messages?

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.