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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:51:50+00:00 2026-05-23T15:51:50+00:00

I have a mysql database table as follows id | uid | touid |

  • 0

I have a mysql database table as follows

id | uid | touid | message | time

This database has the messages sent from one person to another person. I need to fetch the latest messages transferred between me and all other users.

Currently I am using a query as follows:

SELECT uid, touid, message, time
FROM messages
WHERE uid = "'.$currentuser.'"
    OR touid = "'.$currentuser.'"
ORDER by time DESC;

Which will get all the message between me and any other user. But I need to show only the set latest messages transferred between me and all other users.

It tried using GROUP BY but the ordering gets affected. So is there any other solution?

Any ideas? If I am not clear please comment

  • 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-23T15:51:50+00:00Added an answer on May 23, 2026 at 3:51 pm
    SELECT 
      m1.*
    FROM 
      messages m1
     JOIN 
      (SELECT UID, TOUID, MAX(time) time FROM messages GROUP BY UID, TOUID) m2
     ON m1.UID=m2.UID AND m1.TOUID=m2.TOUID and m1.time=m2.time
    WHERE 
      m1.uid = "'.$currentuser.'"
    ORDER BY
      m1.time DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a large mysql database table in which one column contains values ranging
I have a user table in my mysql database that has a password column.
Let's assume that I have a table in a mysql database as follows, date
I currently have a MySQL database with a table that has a field that
I have a MySQL database and a table which has a names column as
I have a table in my database (Mysql) which has 6 columns. I am
I have two tables in my MySQL database, users and tweets, as follows: TABLE
I have a MySQL table named relations, as follows: from to count ------------- A
I have a MySQL table named relations, as follows: from to count ------------- A
I have a MySQL database table with a couple thousand rows. The table is

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.