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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:30:59+00:00 2026-05-31T05:30:59+00:00

I have two tables. One of them called conversations has the following data. ConversationID

  • 0

I have two tables.

One of them called “conversations” has the following data.

ConversationID  Sender     Reciever
1               bla1       bla2
2               bla1       bla3
3               bla1       bla4

The other is called “Messages” has the following data.

MessageID    MessageText    TimeAddedMessage        ConversationID
1             helo           2012-03-12 13:00:00          2
2             helo           2012-03-12 13:01:00          1
3             helo           2012-03-12 13:02:00          3
4             helo           2012-03-12 13:03:00          3
5             helo           2012-03-12 13:04:00          2

The result i want from the query is the following:

5             helo           2012-03-12 13:04:00          2
4             helo           2012-03-12 13:03:00          3
2             helo           2012-03-12 13:01:00          1

Which means that we need the most recent comment for each conversation (sorted DESC by time).

Any help appreciated.

  • 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-31T05:31:00+00:00Added an answer on May 31, 2026 at 5:31 am

    Try –

    SELECT m2.*, c.Sender
    FROM (
        SELECT m1.ConversationID, MAX(m1.MessageID) AS MessageID
        FROM Messages m1
        GROUP BY m1.ConversationID
    ) latest_msg
    INNER JOIN Messages m2
        ON latest_msg.MessageID = m2.MessageID
        AND latest_msg.ConversationID = m2.ConversationID
    INNER JOIN Conversations c
        ON m2.ConversationID = c.ConversationID
    ORDER BY m2.MessageID DESC
    

    EDIT I have modified the above query to include the value of Sender from the Conversations table. I have noticed that your structure for the conversation is a bit odd. A conversation is FROM one user TO another user but there is no way to identify which user wrote each message. Is this intentional?

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

Sidebar

Related Questions

Quick method description: I have two tables, lets name them table ONE and table
I have two tables one called fs_note the other called dumy_fs_note I created after
i have two tables one is called addons and holds information about different addons,
I have two tables, one that has 450 rows, the other is a Sort
Okay, so I have these two tables in MySQL. One is called 'History' and
Okay, so I have these two tables in MySQL. One is called 'History' and
I have a two tables. One has manufacturer information and includes the regions where
I have two tables, one is called video_2, one is called vlan. Table vlan
I have two tables in sql server 2008 R2. one table has records as
I have two tables one called Point and other called Poly i have around

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.