So, I got this statement that works fine:
SELECT MAX(patient_history_date_bio) AS med_date, medication_name FROM biological WHERE patient_id = 12) GROUP BY medication_name
But I would also like to have the appropriate medication_dose. Therefore i type this
SELECT MAX(patient_history_date_bio) AS med_date, medication_name, medication_dose FROM biological WHERE (patient_id = 12) GROUP BY medication_name
But this gives me an error:
"coumn" bio.medication_dose "is not allowed in the select list because it is not contained in the aggregate function or in the GROUP BY clause."
So I try to add medication_dose to the GROUP BY clause, but then it gives me extra lines that I don't need. I would like to get the last row for each medicine in my table. (The last line is determined by the max function, getting the last date).
How to fix this problem?
source share