I came across many similar posts, but none of them found this specific one.
Here is my details:
ID CID NARID NATID NADate EID AEDate
1 1655 1 4 12/1/12 202 6/4/14 11:37:01
2 1655 1 7 12/1/12 202 6/4/14 11:37:12
5 1655 2 65 1/13/14 587 6/4/14 11:37:00
29 3165 1 6 4/15/14 7 6/4/14 11:37:00
300 3165 1 6 6/30/14 7 6/4/14 11:33:50
295 3165 2 64 6/11/14 7 6/4/14 11:37:00
302 3165 2 63 7/24/14 7 6/4/14 11:41:24
303 3165 2 67 7/24/14 7 6/4/14 15:59:06
First, I am looking to get the maximum NADate for each CID and NARID:
ID CID NARID NATID NADate EID AEDate
1 1655 1 4 12/1/12 202 6/4/14 11:37:01
2 1655 1 7 12/1/12 202 6/4/14 11:37:12
5 1655 2 65 1/13/14 587 6/4/14 11:37:00
300 3165 1 6 6/30/14 7 6/4/14 11:33:50
302 3165 2 63 7/24/14 7 6/4/14 11:41:24
303 3165 2 67 7/24/14 7 6/4/14 15:59:06
Then from these results, take the record with the maximum AEDate (along with all the other relevant fields):
ID CID NARID NATID NADate EID AEDate
2 1655 1 7 12/1/12 202 6/4/14 11:37:12
5 1655 2 65 1/13/14 587 6/4/14 11:37:00
300 3165 1 6 6/30/14 7 6/4/14 11:33:50
303 3165 2 67 7/24/14 7 6/4/14 15:59:06
The type of database is MSSQL 2005.
source
share