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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:29:08+00:00 2026-06-17T10:29:08+00:00

If i had a table that stored a person’s name, the time it took

  • 0

If i had a table that stored a person’s name, the time it took them to run a mile, and when they ran said mile, what would be the best way to get a person most recent lap-time.

LAPS
____________________________________________
|  name   | lap_time |        date         |
--------------------------------------------
| George  |   20.3   | 2013-01-17 09:17:14 |
| Alex    |   32.2   | 2013-02-17 14:24:32 |         
| Mike    |   16.6   | 2013-01-17 07:57:54 |
| Alex    |   28.5   | 2013-01-17 19:50:21 |
| Mike    |   15.1   | 2013-02-17 12:37:12 |
| Mike    |   14.8   | 2013-03-17 06:58:34 |
''''''''''''''''''''''''''''''''''''''''''''

I’ve been doing it this way, and it has worked for me so far, but I’m curious to know if there is a better way.

SELECT l.lap_time
FROM laps l
INNER JOIN(
    SELECT *, MAX(date) as most_recent
    FROM laps
    WHERE name = 'Alex'
)AS temp ON (
    l.date = temp.most_recent
    AND l.name = temp.name
)

The actual table that i’m using this type of query on is huge, so i’m looking for the most time efficient way of doing it.

  • 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-17T10:29:09+00:00Added an answer on June 17, 2026 at 10:29 am

    This will work for a single name:

    SELECT name, lap_time, date
    FROM laps
    WHERE name = 'Alex'
    ORDER BY date DESC
    LIMIT 1
    

    Result

    | NAME | LAP_TIME |                            DATE |
    -----------------------------------------------------
    | Alex |     32.2 | February, 17 2013 14:24:32+0000 |

    See the demo

    This should work for all names:

    SELECT a.name, b.lap_time, a.date
    FROM
      (SELECT name, MAX(date) AS date FROM laps GROUP BY name) a
    LEFT JOIN laps b 
      ON b.date = a.date AND b.name = a.name
    

    Result

    |   NAME | LAP_TIME |                            DATE |
    -------------------------------------------------------
    |   Alex |     32.2 | February, 17 2013 14:24:32+0000 |
    | George |     20.3 |  January, 17 2013 09:17:14+0000 |
    |   Mike |     14.8 |    March, 17 2013 06:58:34+0000 |

    See the demo

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

Sidebar

Related Questions

I had a bunch of table views that had code duplicated in them. They
I previously had a table that is created using hibernate entities. I am using
I had a nicely striped table with some nifty mouseover effects that was working
I had a table like this id | name ------------------ 1 | SAM1 2
I have an application that has had a single table where all my data
I have a stored proc that produces a table like this: PeriodStart PeriodEnd TotalActive
Hi I had parent table which has ID and some other columns and a
I had a simple table: class test(Base): __tablename__ = 'test' id = Column(Integer, primary_key=True)
If I had the following table. create_table :my_table, :id => false do |t| t.string
I was iterating through a table I had created and getting the first cell

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.