Q

Latest entry based on timestamp

I have a table with userid, attribute_name, value_date_time. I want to report a single row for each user that shows the latest entry in the table based on the timestamp inserted into value_date_time.

I have a table with userid, attribute_name, value_date_time. I want to report a single row for each user that shows the latest entry in the table based on the timestamp inserted into value_date_time. Any help much appreciated.
You'll have to query for the maximum date attribute and then use that to select the record that matches it. Something similar to the following:
SELECT t1.userid,t1.attribute_name,t1.value_date_time
FROM table_name t1, (SELECT t2.userid,t2.attribute_name,
                     MAX(t2.value_date_time) as max_time
                     FROM table_name) t2
WHERE t1.userid=t2.userid AND t1.attribute_name=t2.attribute_name
  AND t1.value_date_time = t2.max_time;
This was last published in April 2006

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close