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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:31:44+00:00 2026-06-17T05:31:44+00:00

Sorry for my bad description but I’m trying to get the latest date for

  • 0

Sorry for my bad description but I’m trying to get the latest date for each person that last ate each fruit. I don’t think I’m grouping it right or there is something I missed totally. Can someone help me with this? Thanks in advance.

T1
+--------+--------+--------+
| person | fruit  |  date  |
+--------+--------+--------+
|  Bob   | apple  | 1-1-13 |
|  Bob   | apple  | 1-4-13 |
|  Bob   | apple  | 1-6-13 |
|  Bob   | orange | 1-2-13 |
|  John  | apple  | 1-3-13 |
|  John  | orange | 1-2-13 |
|  John  | orange | 1-4-13 |
|  John  | orange | 1-9-13 |
+--------+--------+--------+

Results I'm looking for
+--------+--------+--------+
| person | fruit  |  date  |
+--------+--------+--------+
|  Bob   | apple  | 1-6-13 |
|  Bob   | orange | 1-2-13 |
|  John  | apple  | 1-3-13 |
|  John  | orange | 1-9-13 |
+--------+--------+--------+

What I tried from reading similar posts.

SELECT * FROM T1 
  JOIN (
    SELECT person,max(date) AS latest 
      FROM T1 GROUP BY person
    ) T2
  ON T1.person = T2.person AND T1.date = T2.latest

Resulting in
+--------+--------+--------+
| person | fruit  |  date  |
+--------+--------+--------+
|  Bob   | apple  | 1-6-13 |
|  John  | orange | 1-9-13 |
+--------+--------+--------+

How do I get it to separate the fruit column too?

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

    No need for a JOIN here. Simple aggregate with a GROUP BY.

    SELECT person, fruit, DATE_FORMAT(MAX(date), '%c-%e-%y') AS max_date
    FROM T1
    GROUP BY person, fruit
    

    Result

    | PERSON |  FRUIT | MAX_DATE |
    ------------------------------
    |    Bob |  apple |   1-6-13 |
    |    Bob | orange |   1-2-13 |
    |   John |  apple |   1-3-13 |
    |   John | orange |   1-9-13 |

    See it in action

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

Sidebar

Related Questions

Sorry for the bad heading but I couldnt explain it better. im trying to
first of all I am sorry for the bad description, but I really don't
Greetings, everyone: Firstly, sorry that my Flow description is long winded, but I think
Sorry for the bad title and description, but I was wondering if there is
sorry for bad english. i want to read element with a id but no
FIXED I'm sorry for the bad title, but I spend 5 minuits on it
I am sorry for my bad english. I just try to description my question.
I'm trying to populate class A (sorry for bad naming), with data from EF
sorry for bad Subject of topic but i couldnt find out what to write
Sorry for bad description, i am expecting the following output: FolderA FolderB FolderC The

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.