* Using subquery SELECT driver_id, status, updt ; FROM temp2 ; WHERE driver_id + DTOS(updt) IN ( ; SELECT driver_id + DTOS(MIN(updt)) ; FROM temp2 ; GROUP BY driver_id) ; INTO CURSOR crsResult * Using correlated query SELECT driver_id, status, updt ; FROM temp2 tm1 ; WHERE updt IN ( ; SELECT MIN(updt) ; FROM temp2 tm2 ; WHERE tm2.driver_id = tm1.driver_id) ; INTO CURSOR crsResult>I have a table that records changes to the status of a driver. I need to find the earliest record for each driver and what their status was on that day. I want to put this into a cursor for processing. I have tried an SQL Select statement, but it does not seem to work the way I want it to.
>Driver_id status updt
>0001 A 01/01/2002
>0002 C 01/02/2002
>0003 I 01/02/2002
>0001 B 01/05/2002
>0001 C 01/07/2002
>0003 A 01/08/2002
>
>>Driver_id status updt
>0001 A 01/01/2002
>0002 C 01/02/2002
>0003 I 01/02/2002
>
>>select driver_id, status, min(updt) as updt ; > from temp2 ; > group by 1 ; > into cursor t1 >>
>Driver_id status updt
>0001 C 01/01/2002
>0002 C 01/02/2002
>0003 A 01/02/2002
>
>
>Where the updt is correct but the status is from the last record for the driver.