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.

    Requires Free Membership to View

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 first published in April 2006

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.