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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:13:23+00:00 2026-05-13T13:13:23+00:00

I want to do query as below. Query is wrong but describes my intentions.

  • 0

I want to do query as below. Query is wrong but describes my intentions.

SELECT name, dateTime, data
FROM Record
WHERE dateTime = MAX(dateTime)

Update: Ok. The query describes intentions not quite good. My bad.

I want to select latest record for each person.

  • 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-13T13:13:23+00:00Added an answer on May 13, 2026 at 1:13 pm

    I like Miky’s answer and the from Quassnoi (and upvoted Miky’s) but, if your needs are similar to mine, you should keep in mind some limitations. First and most importantly, it only works if you are looking for the latest record overall or the latest record for a single name. If you want the latest record for each person in a set (one record per person but the latest record for each) then the above solutions fall short. Second, and less importantly, if you’ll be working with large datasets, might prove a bit slow over the long run. So, what is the work-around?

    What I do is to add a bit field to the table marked “newest.” Then, when I store a record (which is done in a stored procedure in SQL Server) I follow this pattern:

    Update Table Set Newest=0 Where Name=@Name
    Insert into Table (Name, dateTimeVal, Data, Newest) Values (@Name, GetDate(), @Data, 1);
    

    Also, there is an index on Name and Newest to make Selects very fast.

    Then the Select is just:

    Select dateTimeVal, Data From Table Where (Name=@Name) and (Newest=1);
    

    A select for a group will be something like:

    Select Name, dateTimeVal, Data from Table Where (Newest=1);  -- Gets multiple records
    

    If the records may not be entered in date order, then your logic is a little bit different:

    Update Table Set Newest=0 Where Name=@Name
    Insert into Table (Name, dateTimeVal, Data, Newest) Values (@Name, GetDate(), @Data, 0); -- NOTE ZERO
    Update Table Set Newest=1 Where dateTimeVal=(Select Max(dateTimeVal) From Table Where Name=@Name);
    

    The rest stays the same.

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

Sidebar

Related Questions

I've got a query below. I want to add a condition that if the
I want to query Active Directory from Windows PE 2.0, which is not supported
I want to query the name of all columns of a table. I found
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I want to create a database query string which should be like this, (SELECT
im joining and retrieving values from two tables using the below query. It displays
I'm trying to remove query strings from my calendar, but my mod_rewrite is not
I want to get phone no of the person from his name which are
I want to query a number of different databases mainly Oracle and Informix. Can
I want a query that returns a list of all the (user) stored procedures

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.