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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:20:43+00:00 2026-05-13T10:20:43+00:00

I am stuck with the following query, which won’t order by it’s date. Any

  • 0

I am stuck with the following query, which won’t order by it’s date. Any help, or insight into what I am doing wrong will be much appreciated. The query is supposed to get an entry by thread_id, and then show the newest post in the thread, much like with a forum post, which it does fine. But when I try to order the results from newest to oldest using ORDER BY clause, it seems to ignore it.

$query = "SELECT * 
          FROM messages 
            WHERE (thread_id, received) 
             IN (SELECT thread_id, MAX(received) 
                 FROM messages 
                 WHERE receiver='$user' OR sender='$user' 
                   AND is_hidden_receiver!='1' 
                 GROUP BY thread_id) 
           ORDER BY received DESC";

Cheers, Lea

  • 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-13T10:20:43+00:00Added an answer on May 13, 2026 at 10:20 am

    You were using the PHP time() function to generate a value to be inserted into an INT(11) column. I’m a little mystified as to why this was sorting incorrectly. I will update this answer if I figure out how to explain it concisely.

    This feature is built into MySQL, it is the TIMESTAMP column type. You should probably read up on it a bit more before being happy with this solution. It has some interesting properties, depending on how to define your table, a column of type TIMESTAMP can act either as a creation timestamp or a modification timestamp.

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

Sidebar

Related Questions

I'm stuck with the following scenario and appreciate any help/advice.. Requirement I have number
I'm stuck on a MDX query... I have a table which looks like: Date
I'm stuck on a MDX query, I'm trying to retrieve the following results: [Time].[2009]
How would I combine (stack vertically) the following 3 queries into one query that
I am trying to use Hibernate+Spring in my application but stuck into following error:
I'm a bit stuck on the following linq query. I'm trying to find all
I'm stuck trying to remove the nested part from the following query : SELECT
I'm stuck with a query I need to write. Given the following model: public
I have the following queries which calculates the total order sale happened in last
I am stuck with this following problem. Say, I have a request which has

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.