Every once in a while I need to do this type of query and I don't seem to know the best way to do it.
I have a table with fields like these...
PatientID
VisitDate
InsuranceType
InsuranceCompanyName
InsurancePlanName
I want to end up with a single record for each PatientID that contains the information from the most recent date. I can easily create the initial query for putting the items in the order I want so that the record I want to select for each patient is the first on in the result for each PatientID, but then I'm not sure how to best select only the first record from this initial query for each patient when trying to join this result set with the Patients table.
A possible added issue is that there can be more than one record in the initial source with the same PatientID and VisitDate, so I am also sorting the initial data by the InsuranceType field as well to determine which record comes first in the inital query.
There has to be a standard technique for doing this sort of thing...
I have a table with fields like these...
PatientID
VisitDate
InsuranceType
InsuranceCompanyName
InsurancePlanName
I want to end up with a single record for each PatientID that contains the information from the most recent date. I can easily create the initial query for putting the items in the order I want so that the record I want to select for each patient is the first on in the result for each PatientID, but then I'm not sure how to best select only the first record from this initial query for each patient when trying to join this result set with the Patients table.
A possible added issue is that there can be more than one record in the initial source with the same PatientID and VisitDate, so I am also sorting the initial data by the InsuranceType field as well to determine which record comes first in the inital query.
There has to be a standard technique for doing this sort of thing...