I copied this query from MS Access and was able to clean it up in SQL. The table tblFactReferrals has multiple records for each patient. Each patient usually has about 4 records with the same referral date. I only need one record from each. This shows all of them. The field table tblFactReferrals.ReferralStatus has the word Initiated in one record. The others do not. Can you advise on this?
BEGINNING OF CODE
SELECT MIN(tblFactReferrals.ReferralDate) AS MinOfReferralDate, tblDimPatients.LastContactDate, tblDimPatients.PatientID, tblDimPatients.LastName,
tblDimPatients.FirstName, tblDimPatients.MInitial, tblDimPatients.Suffix, tblDimPatients.MedicalRecordNumber, tblDimPatients.GraduatingYear
FROM tblDimPatients INNER JOIN
tblFactReferrals ON tblDimPatients.PatientID = tblFactReferrals.PatientID
GROUP BY tblDimPatients.LastContactDate, tblDimPatients.PatientID, tblDimPatients.LastName, tblDimPatients.FirstName, tblDimPatients.MInitial, tblDimPatients.Suffix,
tblDimPatients.MedicalRecordNumber, tblDimPatients.GraduatingYear, tblDimPatients.Status
HAVING (tblDimPatients.Status = 'Referral')
ORDER BY MinOfReferralDate DESC, tblDimPatients.LastName, tblDimPatients.FirstName, tblDimPatients.MInitial, tblDimPatients.Suffix
END OF CODE
Thank you.