ljoekelsoey4
Registered User.
- Local time
- Today, 15:24
- Joined
- Mar 16, 2017
- Messages
- 49
Hello,
I realise this is a fairly common issue and have found some help on google, however the reasing/code behind the answer is fairly confusing to me unfortunately.
I’m trying to create a query to pull a list of all patients’ most recent appointments. I’ve a base query of ‘active patients’ (alive, not discharged to another hospital, etc) upon which I run all other queries, including this one.
This is what the ‘ActivePatient’ query looks like
ApptID Patient ID Appointment Date Attended? Follow Up Date
1 1 01/02/2017 Yes 01/02/2018
2 2 01/02/2017 Yes 01/02/2018
3 2 15/09/2016 Yes 01/02/2017
4 2 15/07/2016 No 15/09/2016
5 3 21/02/2017 No 21/02/2018
6 3 13/01/2017 Yes 21/02/2017
7 3 14/08/2016 No 13/01/2017
8 3 02/03/2016 No 14/08/2016
When I run the ‘most recent appointment’ query I get;
ApptID Patient ID Appointment Date Attended? Follow Up Date
1 1 01/02/2017 Yes 01/02/2018
2 2 01/02/2017 Yes 01/02/2018
4 2 15/07/2016 No 15/09/2016
5 3 21/02/2017 No 21/02/2018
6 3 13/01/2017 Yes 21/02/2017
…but what I actually want is…
ApptID Patient ID Appointment Date Attended? Follow Up Date
1 1 01/02/2017 Yes 01/02/2018
2 2 01/02/2017 Yes 01/02/2018
5 3 21/02/2017 No 21/02/2018
Heres the SQL code;
“
SELECT qyrPatientsActive.Patient ID, qyrPatientsActive.Surname, qyrPatientsActive.[First Name], Max(tblAppointments.[Appointment Date]) AS [MaxOfAppointment Date], tblAppointments.[Attended?]
FROM qyrPatientsActive INNER JOIN tblAppointments ON qyrPatientsActive.Patient ID = tblAppointments.Patient ID
GROUP BY qyrPatientsActive.Patient ID, qyrPatientsActive.Surname, qyrPatientsActive.[First Name], tblAppointments.[Attended?]
ORDER BY qyrPatientsActive.Surname;
“
Thanks guys
I realise this is a fairly common issue and have found some help on google, however the reasing/code behind the answer is fairly confusing to me unfortunately.
I’m trying to create a query to pull a list of all patients’ most recent appointments. I’ve a base query of ‘active patients’ (alive, not discharged to another hospital, etc) upon which I run all other queries, including this one.
This is what the ‘ActivePatient’ query looks like
ApptID Patient ID Appointment Date Attended? Follow Up Date
1 1 01/02/2017 Yes 01/02/2018
2 2 01/02/2017 Yes 01/02/2018
3 2 15/09/2016 Yes 01/02/2017
4 2 15/07/2016 No 15/09/2016
5 3 21/02/2017 No 21/02/2018
6 3 13/01/2017 Yes 21/02/2017
7 3 14/08/2016 No 13/01/2017
8 3 02/03/2016 No 14/08/2016
When I run the ‘most recent appointment’ query I get;
ApptID Patient ID Appointment Date Attended? Follow Up Date
1 1 01/02/2017 Yes 01/02/2018
2 2 01/02/2017 Yes 01/02/2018
4 2 15/07/2016 No 15/09/2016
5 3 21/02/2017 No 21/02/2018
6 3 13/01/2017 Yes 21/02/2017
…but what I actually want is…
ApptID Patient ID Appointment Date Attended? Follow Up Date
1 1 01/02/2017 Yes 01/02/2018
2 2 01/02/2017 Yes 01/02/2018
5 3 21/02/2017 No 21/02/2018
Heres the SQL code;
“
SELECT qyrPatientsActive.Patient ID, qyrPatientsActive.Surname, qyrPatientsActive.[First Name], Max(tblAppointments.[Appointment Date]) AS [MaxOfAppointment Date], tblAppointments.[Attended?]
FROM qyrPatientsActive INNER JOIN tblAppointments ON qyrPatientsActive.Patient ID = tblAppointments.Patient ID
GROUP BY qyrPatientsActive.Patient ID, qyrPatientsActive.Surname, qyrPatientsActive.[First Name], tblAppointments.[Attended?]
ORDER BY qyrPatientsActive.Surname;
“
Thanks guys