ljoekelsoey4
Registered User.
- Local time
- Today, 08:18
- Joined
- Mar 16, 2017
- Messages
- 49
I've two tables, tblPatients where the primary key is PatientID, and tblAppointments where the primary key is AppointmentID;
I've multiple appointment entries for each patient, as well as a follow up date for when the next appointment is to be booked. When trying to create a 'max of' query for appointment date, the query is returning 2 appointment records for each patient record; one is the max of appointment with the follow up date field empty, and the other is the max appointment date with the follow up date not empty. I want to return the max of appointment regardless of follow up date, but i need to be able to see what the follow up date is in the query result.
Thanks for your help!
SQL:
SELECT tblAppointments.PatientID, Max(tblAppointments.AppointmentDate) AS MaxOfAppointmentDate, tblAppointments.FollowUpDate
FROM tblAppointments
GROUP BY tblAppointments.PatientID, tblAppointments.FollowUpDate
ORDER BY tblAppointments.PatientID;
I've multiple appointment entries for each patient, as well as a follow up date for when the next appointment is to be booked. When trying to create a 'max of' query for appointment date, the query is returning 2 appointment records for each patient record; one is the max of appointment with the follow up date field empty, and the other is the max appointment date with the follow up date not empty. I want to return the max of appointment regardless of follow up date, but i need to be able to see what the follow up date is in the query result.
Thanks for your help!
SQL:
SELECT tblAppointments.PatientID, Max(tblAppointments.AppointmentDate) AS MaxOfAppointmentDate, tblAppointments.FollowUpDate
FROM tblAppointments
GROUP BY tblAppointments.PatientID, tblAppointments.FollowUpDate
ORDER BY tblAppointments.PatientID;