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

  • Home
  • SEARCH
  • 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 7528511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:24:05+00:00 2026-05-30T04:24:05+00:00

table: chat_thread +———–+———-+——————–+ | id | title | date | +———–+———-+——————–+ | 1 |

  • 0
table: chat_thread

+-----------+----------+--------------------+
|        id | title    |             date   |
+-----------+----------+--------------------+
|         1 | Thread 1 | 2012-02-16 01:12:40| 
|         2 | Thread 2 | 2012-02-17 02:32:44| 
+-----------+----------+--------------------+

table: chat_comment

+-----------+----------+--------------------+
|        id | t_id     |             date   |
+-----------+----------+--------------------+
|         1 | 1        | 2012-02-19 19:45:32| 
|         2 | 1        | 2012-02-15 22:29:20| 
+-----------+----------+--------------------+

Here’s my situation, I creating a basic forum with threads and comments. I want to order by the last comment date, and if there is no comments, then the thread start date. The problem I’m having is trying to echo out the last reply date in my while loop.

mysql_query("
SELECT *,
chat_comment.date AS commentDate,
chat_thread.date AS threadDate
FROM chat_thread
LEFT JOIN chat_comment ON chat_thread.id = chat_comment.t_id
GROUP BY chat_thread.id
ORDER BY commentDate DESC, threadDate DESC");

My issue isn’t the correct order of the threads, but the comment dates. In my tables above, if I’m trying to echo out the date, I’m currently getting 2012-02-15 22:29:20 instead of the more recent 2012-02-19 19:45:32.

Is there something I’m doing wrong?

I think it has something to do with the GROUP BY, because if I change it to GROUP BY chat_comment.date then the dates in the while loop are accurate, but there are duplicates, because I am not grouping by the chat_thread.id

  • 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-30T04:24:06+00:00Added an answer on May 30, 2026 at 4:24 am

    Instead of selecting the last chat_comment.date, you are selecting an arbitrary one. (See MySQL Reference Manual, §11.6.3: GROUP BY and HAVING with Hidden Columns for a detailed explanation of this.) You need to use MAX(chat_comment.date) instead of just chat_comment.date.

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

Sidebar

Related Questions

Table: UserId, Value, Date. I want to get the UserId, Value for the max(Date)
Table structure- int PrimaryKey DateTime Date int Price What I would like to do
Table has the following info: date |vendor|sales|percent| -------------------------- 2009-03-03| 10 |13.50| 1.30 | 2009-03-10|
I am creating chat app by using web services. Here I am going to
I'm creating a chat system but the user table is from a seperate database.
Here is a multilang table design. Is it possible to add a method for
I'm developping a chat application. I want to keep everything logged into a table
table data of 2 columns category and subcategory i want to get a collection
table { id: long name: string } 1235 Fred 1902 Trever 5123 George 6467
**Table A** 1 2 3 4 5 6 **Table B** 2 3 5 How

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.