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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:00:02+00:00 2026-05-28T02:00:02+00:00

I have the following database table (People): +——–+——–+——–+ | Name | Age | Time

  • 0

I have the following database table (People):

+--------+--------+--------+
|  Name  |   Age  |  Time  |
+--------+--------+--------+
| Tim    |   30   |  10:10 |
| Jill   |   31   |  10:20 |
| Peter  |   31   |  10:30 |
| Peter  |   33   |  10:40 |
| Jack   |   32   |  10:50 |
| Susan  |   35   |  10:60 |
| Susan  |   35   |  11:70 |
+--------+--------+--------+ 

Now I want to get 5 names which are the oldest from this list:

Select * FROM People ORDER BY Age DESC LIMIT 5

This will give:

| Susan  |   35   |  11:70 |
| Susan  |   35   |  10:60 |
| Peter  |   33   |  10:40 |
| Jack   |   32   |  10:50 |
| Peter  |   31   |  10:30 |

Now this is not exactly what I want. We see Susan in there twice, same as Peter. I don’t want duplicate names to show up. Now we see that the 2 Susans have both the same age, so the Susan with the highest time (mm:ss) should be filter out (in this case: | Susan | 35 | 11:70 |)

Fot the 2 Peters we see that one Peter is older, so in this case the younger Peter should be filtered out (| Peter | 31 | 10:30 |)

So how would this Query look like? It should first select all, then order them by Age (oldest on top), then filter out the duplicate names where it must first look at the age (lowest gets filtered) and then at the time (highest time gets filter out) and then DESC LIMIT 5.

So the only correct result will look like this:

| Susan  |   35   |  10:60 |
| Peter  |   33   |  10:40 |
| Jack   |   32   |  10:50 |
| Jill   |   31   |  10:20 |
| Peter  |   31   |  10:30 |
  • 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-28T02:00:03+00:00Added an answer on May 28, 2026 at 2:00 am
    SELECT
        Name, Age, MIN(Time) As LowestTime
    FROM
        People
    GROUP BY 
        Name, Age
    ORDER BY
        Age DESC, Name ASC
    LIMIT 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following database table with information about people, diseases, and drugs: PERSON_T
I have the following database table with information about people, diseases, and drugs: PERSON_T
I have a table named People in the following format: Date | Name .
Let's say I have the following database table: record_id | record_date | record_value -----------+-------------+--------------
I have the following listbox below which binds to a database table of image
I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation
I have the following table and sequence in my postgresql-8.4 database: CREATE TABLE complexobjectpy
Say I have a database table like the following: FileID | FileName | FileSize
I have the following table in my database. Now what I want to find
I have the following table in my postgreSQL 8.3.14 database timestamp status 2012-03-12 19:15:01

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.