I have a column xdate, column seqnumber, personID
I want 1 record per personID, where it is the most recent xdate max(xdate)
if there is multiple same max xdates i want it to look then for the max seqnumber to determine what row to pull.
obviously this doesn't work:
select max(xdate), max(seqnumber), personID From table1
Group by personID
1 person can have many records, 1 person can have the many of the same xdate, but seqnumber iterates for each xdate starting with 0 going to n
I can't quite figure this out, I can't use a correlated sub-query because there are many records. I would need to join I believe.
Example data above, I would want the results of the
1st row
3rd row
6th row
Please help,
mike
Best Answer
You don't mention DBMS, so I'll assume it is one that supports window functions (DB2, Oracle, SQL-server, Postgres, etc)
Edit: added sample data and result (http://sqlfiddle.com/#!4/73ad2/4)