In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
CREATE INDEX appt_idx_patientid ON Appt (PatientID);
CREATE INDEX apptcpt_idx_apptid ON ApptCPT (ApptID);
SELECT
p.ID AS PatientID,
MAX(ac.ID) AS ApptCPTID,
ac.CPTID
FROM
Patient p
INNER JOIN
Appt a
ON a.PatientID = p.ID
INNER JOIN
ApptCPT ac
ON ac.ApptID = a.ID
GROUP BY
p.ID,
ac.CPTID
ORDER BY
p.ID,
ac.CPTID