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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:20:11+00:00 2026-06-09T18:20:11+00:00

I have a database where I keep mail conversations table conversations ID SUBJECT 1

  • 0

I have a database where I keep mail conversations

table "conversations"
ID    SUBJECT
1     meeting on Friday

table "conversations_mails"
ID    CONVERSATION_ID    TEXT                               CREATED_ON
1     1                  "What about a meeting on Friday?"  2012-08-05 10:00:00
2     1                  "that's a good idea!"              2012-08-10 15:00:00

Now, i want to display a conversation overview page, showing a truncated text version of the latest reply. eg

"Meeting on Friday"
That's a good ... 

I try to achieve this via GROUP BY. But what I get is the first reply in the table (“What about a meeting on Friday”), instead of the last “That’s a good Idea”.

This is my SQL statement:

SELECT *, MAX(conversations_mails.created_on) As conversation_last_reply,
  MAX(conversations_mails.id) AS maxId
FROM conversations 
LEFT JOIN conversations_mails ON conversations_mails.conversation_id = conversations.id 
GROUP BY conversations.id 
ORDER BY conversation_last_reply DESC

I know how to get the highest ID via MAX(), but what about the corresponding TEXT entry?

Thank you!

  • 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-09T18:20:13+00:00Added an answer on June 9, 2026 at 6:20 pm

    Try this-

    SELECT *, MAX(conversations_mails.created_on) As conversation_last_reply,
      MAX(conversations_mails.id) AS maxId
    FROM conversations 
    LEFT JOIN conversations_mails ON conversations_mails.conversation_id = conversations.id 
    WHERE conversations_mails.id = (select max(conversations_mails.id) from conversations_mails where conversations_mails.conversation_id = conversations.id)
    GROUP BY conversations.id 
    ORDER BY conversation_last_reply DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Product table in a shopping site's database to keep
I have an sqlite database, and I would like to keep it read-only without
I have read that you should keep the number of connections in your database
I am creating a database that will help keep track of which employees have
On my MySQL database, I have a unsigned mediumint column, which I keep incrementing
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database with an status field that can keep the following values:
I have a database table of topics that changes frequently. Let's say the table
I have a Database containes information about all the branches of our company around
I have a database with a bunch of links that I want to keep

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.