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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:52:37+00:00 2026-06-13T17:52:37+00:00

I am coding a message system for user communication. In the inbox I do

  • 0

I am coding a message system for user communication. In the inbox I do not want to show the user the messages he/she received. I just want to show the conversations. So as an example, if one user send or receive more than one message then in the inbox there should only be the conversation (which includes the newest message, either written or received) with the user and when the user clicks on the conversation he/she can see all past messages.

The table structure (simplified) of ‘messages’ is as followed:

message_id
user_id_sender
user_id_recipient
message

Now the problem is that the messages are saved in a database where each row is one message, so I have to group these messages in a certain way.

The select statement I came up with is the following:

SELECT * FROM messages
WHERE user_id_sender = 1 OR user_id_recipient = 1
GROUP BY user_id_sender

But now I obviously get two messages because one which has been written by user ‘1’ and one that he has received..

Does anybody have an idea how to solve this?

  • 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-13T17:52:38+00:00Added an answer on June 13, 2026 at 5:52 pm

    I’ve solved this problem some month ago. I suppose you have also a date field. This query give you a well structured results with date of last message and last message.

    $qry = 'SELECT 
    CONCAT(GREATEST(user_id_sender,user_id_recipient)," ",LEAST(user_id_sender,user_id_recipient)) AS thread, 
    MAX(CONCAT(date,"|",message)) as date_message, 
    MAX(date) AS last_message, 
    messages.* 
         FROM messages
         WHERE user_id_sender= ? || user_id_recipient=? GROUP BY thread ORDER BY last_message DESC';
    
    $rows = $db->fetchAll($qry, Array($current_user_id,$current_user_id));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am coding a message distribution system. Server is ColdFusion (CF) 10, using the
I am coding for a Netty based Notifying Server, which takes in Message Buffer
I'm coding an android app for parsing sms messages. I need different rules for
I've been able to finally get python-openid to authenticate a user, but I'm not
I am currently working on a private messaging system. Right now I'm coding the
I built a very simple chat system... it works great and when the user
I want to use a case statement in my user-defined functions because I need
i am creating a system. What i want to know is if a msg
I am coding a rcon message tool for a game server in C#. However
I'm seeing this exception message coming from XslCompiledTransform.Transform(), but after handling the exception the

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.