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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:14:01+00:00 2026-05-25T15:14:01+00:00

I want to select the latest rows of a specific table that has 5

  • 0

I want to select the latest rows of a specific table that has 5 items in MySQL.
The table looks like:

  • id (auto increase)
  • to
  • from
  • time stamp
  • text

The data is something like:

|id | to     | from   | time stamp | text
| 1 | user01 | user02 | 2011-09-01 | text1
| 2 | user01 | user02 | 2011-09-02 | text2
| 3 | user02 | user01 | 2011-09-02 | text3
| 4 | user01 | user03 | 2011-09-03 | text4
| 5 | user01 | user04 | 2011-09-03 | text5
| 6 | user01 | user03 | 2011-09-04 | text6
| 7 | user03 | user01 | 2011-09-05 | text7

I want to select * WHERE to = 'user01' and the latest data (maybe by “id” or “time stamp”). The “from” can be numerous but each same “from” data can appear just once.


Anyway, the selected data will be:

| 2 | user01 | user02 | 2011-09-02 | text2
| 5 | user01 | user04 | 2011-09-03 | text5
| 6 | user01 | user03 | 2011-09-04 | text6

Could it be done?
Thanks for taking time reading my question 🙂

  • 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-25T15:14:01+00:00Added an answer on May 25, 2026 at 3:14 pm
    SELECT t.* 
    FROM
          TableX AS t
      JOIN
          ( SELECT DISTINCT `from` AS f
            FROM TableX
            WHERE `to` = 'user01'
          ) AS df
        ON 
          t.id = ( SELECT tt.id
                   FROM TableX AS tt
                   WHERE tt.`to` = 'user01'
                     AND tt.`from` = df.f
                   ORDER BY tt.`timestamp` DESC
                   LIMIT 1
                 )
    

    It’s better to avoid naming tables and fields with keywords like to, from and timestamp.

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

Sidebar

Related Questions

I want to select one record at a time from a MySQL table. I
I have a table that get its rows from a MYSQL database <table id=table1>
i have users table and i have posts table i want select from users
I want to extract rows of group by rls_id but with latest/recent date SELECT
What i want, to display rows from a table which is selected by a
I need to get the latest X rows. So I do something like SELECT
I want to return 3 rows from a table called cars and each car
I want to get the remaining/latest balance of the cardnumber from the rows. Below
I am trying to select of the duplicate rows in mysql table it's working
SELECT NameMonth,Year,Value from Table WHERE Name LIKE '%JERRY%' AND Year = (SELECT MAX(Year) FROM

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.