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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:36:54+00:00 2026-06-11T00:36:54+00:00

I have a table chat . The column are id, sender, message, time, sender_email

  • 0

I have a table chat.
The column are "id", "sender", "message", "time", "sender_email".
Some chat history which inserted into chat like:

1 John hihi 10:45 john@email.com
2 John hihi 10:46 john@email.com
3 Peter hihi 10:47 peter@email.com
4 John hihi 10:48 john@email.com
5 John hihi 10:49 john@email.com
6 John hihi 10:50 john@email.com
7 Mary hihi 10:51 mary@email.com
8 John hihi 10:52 john@email.com
9 Peter hihi 10:53 peter@email.com
10 John hihi 10:54 john@email.com

I would like to get the last message from people who appeared in the table.
If there is one who appear in the table many time, just get his last message.
So the result I would like to get should be:

10 John hihi 10:54 john@email.com
9 Peter hihi 10:53 peter@email.com
7 Mary hihi 10:51 mary@email.com

Is it possible to do so??
So far, I just write a sql:

SELECT DISTINCT name from chat ORDER BY id DESC

But seems it cannot display what I want.

  • 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-11T00:36:55+00:00Added an answer on June 11, 2026 at 12:36 am

    You have to determine which messages are the last one for each user (I’m doing this by time but you could do it by id too if you know a higher value definitely equals a later message), then get that message’s data:

    SELECT chat.*
    FROM chat
    INNER JOIN
    (
        SELECT MAX(time) AS time, sender
        FROM chat
        GROUP BY sender
    ) lastMsg ON chat.time = lastMsg.time AND chat.sender = lastMsg.sender
    

    This also assumes there are no ties for time. If this is possible you’ll have to go by id instead:

    SELECT chat.*
    FROM chat
    INNER JOIN
    (
        SELECT MAX(id) AS id
        FROM chat
        GROUP BY sender
    ) lastMsg ON chat.id = lastMsg.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database in MYSQL and it has chat table which looks like
I have table in which I am inserting rows for employee but next time
I have table and this table contain result column with some entries. I just
i am coding something like omegle random chat i have a table called chat_users
I have hasMany Through table which is Chats table with Chat model and I'm
okay, i'm setting up a multi-user chat system. i have a messages table, that
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
I have this kind of table for simple chat: messages table structure +----+---------+-----------+---------+------+------+ |
Have table and several div elements. Table is time grid and divs are events
How do you load a database column into a list with Django? I have

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.