I have the following query
-------
SELECT
e.encounterID,
e.patientID,
p.ControlNo
e.date AS Enc_date,
e.facilityId
FROM enc e
INNER JOIN patients p
ON e.patientID = p.pid
INNER JOIN users u
ON p.piD = u.uid
WHERE (((e.date) >= DATE_SUB(NOW(), INTERVAL 24 MONTH)) AND ((e.encType)=1) AND ((e.encLock)=1))
AND (e.facilityId IN (12,37,14,18,19,13,16,36))AND ((u.delFlag) =0)
--------
all I want to do is get the last Enc_date, with encounterID and patientID.
I know I need to use a subquery w/ a inner join.
I just dont understand how to put it together. Could someone please help me get the max date with related coulmns and help explain it to me. I reviewed this forum and was able to get a max query, but I dont know how to put it together.
thanks in advance
-------
SELECT
e.encounterID,
e.patientID,
p.ControlNo
e.date AS Enc_date,
e.facilityId
FROM enc e
INNER JOIN patients p
ON e.patientID = p.pid
INNER JOIN users u
ON p.piD = u.uid
WHERE (((e.date) >= DATE_SUB(NOW(), INTERVAL 24 MONTH)) AND ((e.encType)=1) AND ((e.encLock)=1))
AND (e.facilityId IN (12,37,14,18,19,13,16,36))AND ((u.delFlag) =0)
--------
all I want to do is get the last Enc_date, with encounterID and patientID.
I know I need to use a subquery w/ a inner join.
I just dont understand how to put it together. Could someone please help me get the max date with related coulmns and help explain it to me. I reviewed this forum and was able to get a max query, but I dont know how to put it together.
thanks in advance