I have a number of database records for experiments taken a number of weeks apart from each other, usually approximately 2-3 weeks apart. The goal is to select the most recent results by date to generate a report. Here is an example dataset. For this dataset the goal is to pick the last row since it is the most recent measurement taken for the QL_ID
P14404
.
QL_ID
is the primary key and QL_VAL
are the measurements for the sample and MEASUREMENT_DATE
is the date the measurements were taken. The table name is QL_RESULTS
. I am able to get the most recent date and the QL_ID
by using the query below, but I'm stuck on how to get all 3 columns i.e. QL_VAL,QL_ID,MEASUREMENT_DATE
.
SELECT QL_ID,MAX(MEASUREMENT_DATE) FROM QL_RESULTS
GROUP BY QL_ID
QL_VAL QL_ID MEASUREMENT_DATE
25 P14404 01-JUL-10
30 P14404 15-JUL-10
21 P14404 29-JUN-10