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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:46:33+00:00 2026-06-10T00:46:33+00:00

I have a table in mysql where it stores the messages between users. The

  • 0

I have a table in mysql where it stores the messages between users.
The Table has the following fields:

ID   from_memberID  to_memberID   message                 Date
+----+--------------+------------+-----------------------+-----------------------+
1         205          207         hello Peter           19/08/2012 20:00:00
2         207          205         Hi frank              19/08/2012 20:01:00
3         205          208         hello Jennifer        19/08/2012 20:10:00
4         207          210         hello Peter           19/08/2012 20:20:00

Well, let’s suppose I want to get only last message from each conversation by user 205

it should get registers 2 and 3, the conversation between users(205-207) and users (205-208). The fact is that i use GROUP BY from_memberID and then in my result the register ID=1 is added too.

This is the statement is use:

SELECT *
FROM
(SELECT msg.ID,
    msg.mensaje,
    msg.from_miembroID,
    msg.fecha,
    msg.read,
    FROM mensajes as msg
    INNER JOIN miembros as mem ON mem.ID=IF(msg.from_miembroID=205, msg.to_miembroID, msg.from_miembroID)
WHERE msg.to_miembroID=205 OR msg.from_miembroID=205
ORDER BY msg.fecha DESC) as temp
GROUP BY from_miembroID

how can i use GROUP BY for considering the two columns (from_memberID, to_memberID) to be as one?

Thanks in advance.

  • 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-10T00:46:34+00:00Added an answer on June 10, 2026 at 12:46 am

    You could use a new custom field, ordering the ids (from_memberID, to_memberID) by a custom rule, e.g. the smaller one always comes first.

    For example:

    SELECT 
         IF(from_memberID < to_memberID, 
             CONCAT(from_memberID, '-', to_memberID),
             CONCAT(to_memberID, '-', from_memberID)
         ) as conversation_ids
    FROM `messages`
    

    That field will return unique combinations, e.g. 205-207 no matter if 205 sent a message to 207 or 207 sent a message to 207.

    Finally, you could group by this value and get unique combinations.

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

Sidebar

Related Questions

I have a table called Comments that stores messages between two users, and the
I have mysql table that has a column that stores xml as a string.
I have a MSSQL table stores that has the following columns in a table:
I have a usermessages table in which all messages sent between two users on
I have a table that stores messages from one user to another. messages(user_id,friend_id,message,created_date). My
I have a MYSQL-Table which stores scores. Every time a user improves a new
I have a Mysql table that stores dates in the format (YYYY-MM-DD HH:MM:SS). What
i have a table in mysql db ( created_date). It stores timestamps (INT value).
I have a MySql table called reviews which stores a lot of product reviews,
I have a mysql table field set as time type which stores data in

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.