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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:25:06+00:00 2026-06-03T10:25:06+00:00

I am working on creating a SQL query where the result will return a

  • 0

I am working on creating a SQL query where the result will return a student test score
from the last test that they took. I think that this should be fairly simple but I am just not seeing it.

Here is my test data

Name    Date        Score
John    2/3/2012    94
John    2/14/2012   82
John    2/28/2012   72
Mary    2/3/2012    80
Mary    2/28/2012   71
Ken     2/14/2012   68
Ken     2/14/2012   66

I want the returned result to be

John    2/28/2012   72
Mary    2/28/2012   80
Ken     2/14/2012   66

I appreciate any assistance.

  • 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-03T10:25:21+00:00Added an answer on June 3, 2026 at 10:25 am
    select date, name, score
    from temp t1
    where date = (select max(date) from temp where t1.name = temp.name)
    

    OR

    SELECT a.*
    FROM temp a
    INNER JOIN 
    (
      SELECT name,MAX(date) as max_date 
      FROM temp a
      GROUP BY name
    )b ON (b.name = a.name AND a.date=b.max_date)
    

    Here is a sql fiddle with an example

    or even this if you have more than one record for each person on a date like you show in your sample data.

    SELECT c.name,c.date, MAX(c.score) as max_score
    FROM
    (
     SELECT a.* 
     FROM temp a
     INNER JOIN 
     (
      SELECT name,MAX(date) as max_date 
      FROM temp a
      GROUP BY name
     )b ON (b.name = a.name AND a.date=b.max_date)
    )c
    group by c.name,c.date
    

    Sql fiddle with this example

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

Sidebar

Related Questions

I'm working on creating a SQL query that will pull records from a table
I'm working on creating a domain layer in Zend Framework that is separate from
I'm working on creating a Hibernate query engine that can create dynamic queries. Thus
I'm trying to create a query on SQL server 2005 that will check if
I am working on optimizing a SQL query that goes against a very wide
I'm working with SQL Server 2000 and Java. I am creating an application that,
I have an SQL database with multiple tables, and I am working on creating
I am actually working on SP in SQL 2005. Using SP i am creating
I'm currently working on creating a new C# project that needs to interact with
I've been working on creating a form that submits content into my database but

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.