Selecting most recent record
Hi, I have a table that lists status, date and ID. I am trying to return the most recent status for each ID with a query like this
SELECT K."Clinic ID", K."Stauts Date", K."Status"
FROM "Status" AS K
WHERE K."Stauts Date"=(SELECT MAX(J."Stauts Date") FROM "Status" AS J WHERE J."Clinic ID" = K."Clinic ID")
ORDER BY K."Clinic ID" ASC
Howver I get the error
Invalid column 'Clinic ID' used in SELECT query.
* If its not true, kindly enclose the column name(s) within double quotes (" ") if it has any special characters like white space,-,%...
* If its just a string value enclose it in single quotes (eg. 'John Abraham')
This seems strange as the query works fine when broken down into pieces. As soon as I add the join WHERE J."Clinic ID" = K."Clinic ID" I get the error.
Any Ideas would be of great assistance.
Al