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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:35:19+00:00 2026-06-18T20:35:19+00:00

I have a simple web application that allows users to message each other, the

  • 0

I have a simple web application that allows users to message each other, the user can view their inbox to see their messages. The inbox should be grouped by sender, sorted by date of the latest message from that sender and also by the inbox read status.

I thought my query was working fine however i have just noticed that the ordering of some messages are not correct! I am pretty sure its due to the group by returning any message… is there anyway around this?

Have a look at this fiddle:
http://sqlfiddle.com/#!2/565c6/1

The last message of the sorted inbox, actually has the latest message yet its at the bottom of the inbox view!

  • 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-18T20:35:20+00:00Added an answer on June 18, 2026 at 8:35 pm

    I think you’re looking for a group-wise max:

    SELECT *
    FROM who_messages wm1
    WHERE wm1.sent = (
      SELECT MAX(sent)
      FROM who_messages wm2
      WHERE wm2.from_userid = wm1.from_userid
        AND wm2.to_userid = 41
    )
    ORDER BY wm1.is_read ASC, wm1.sent DESC;
    

    Sql Fiddle

    Or, without the correlated sub-query:

    SELECT *
    FROM who_messages wm1
    JOIN (
      SELECT from_userid, MAX(sent) as sent
      FROM who_messages
      WHERE to_userid = 41
      GROUP BY from_userid
    ) wm2 ON wm1.from_userid = wm2.from_userid AND wm1.sent = wm2.sent
    ORDER BY wm1.is_read ASC, wm1.sent DESC;
    

    Sql Fiddle

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

Sidebar

Related Questions

I have a simple web browser embedded in an application that allows a user
I'm currently working on a simple web application where users each have their own
I have written an ASP.NET MVC application that allows the user to specify their
I have a simple application written that allows users to pick inventory items with
I have an ASP.NET web application that, in part, allows a user to upload
I have a web application that shows a users all of their data bucketed
I have a simple web application which lets the user upload local user data
In my web application, I have users input a date in a simple textbox.
I have a question web application which allows users to ask questions on specific
I want to create a java application that allows users to import a web

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.