I have a table that is a collection entries of users' information:
username, date, sequence, value
--------------------------
Hannah, 1/2/2010, 0, peach
Kim, 1/3/2010, 0, watermelon
Hannah, 8/4/2009, 0, mango
David, 2/2/2010, 0, apple
David, 2/2/2010, 1, orange
David, 1/3/2010, 0, banana
...
I want to create a query that would give me the latest date and then the latest sequence for each user?
For example, the result will be:
Hannah, 1/2/2010, 0, peach
Kim, 1/3/2010, 0, watermelon
David, 2/2/2010, 1, orange
In details of the result, David has two latest data records:
David, 2/2/2010, 0, apple
David, 2/2/2010, 1, orange
and then from these two records, the latest sequence is 1, so the final result is:
David, 2/2/2010, 1, orange
Thank you so much if anyone can help me with this. The table is huge so the query would need to be very efficient, otherwise, it exceeds call limit on CPU usage.