HiGot a data set like this:rowID PersonID Start Date End Date===== ======== ========== ==========001 6575556 19/06/2013 09/07/2013001 6575556 20/06/2013 12/07/2013001 6575556 21/06/2013 12/07/2013002 9478522 15/05/2013 18/05/2013003 7753423 22/08/2013 01/09/2013
Person can have more than one start/end date therefore I get multiple of the same row ID and Person ID when looking at their dates.I want to display the most recent end date and associated data if there is more than one start/end date for the same person. I decided to do a self join with max Date aggregate using this against a main select from the Table1:SELECT PersonID, MAX([End Date]) AS MaxEndDateFROM Table1GROUP BYPersonID
And join it this way:select RowID,PersonID,[End Date]FROM Table1 INNER JOIN (SELECT PersonID,MAX([End Date]) AS MaxEndDateFROM Table1GROUP BYPersonID ) aON Table1.PersonID = a.PersonIDAND Table1.[end Date] = a.MaxEndDate
When I run the sub-query on its own it gives me the single PersonID and Max Date but on self-joining with Table1 I still get the duplicates values.Any thoughts what is wrong with the statement?ThanksG