Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find the records with the earliest dates
Message
 
 
To
15/01/2003 16:33:38
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00742121
Message ID:
00742135
Views:
15
This message has been marked as the solution to the initial question of the thread.
Mark,

There'e a couple ways you can do that.
* 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.
>
>If the records I have are:
>
>
>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
>
>
>I want to get a cursor with:
>
>
>Driver_id   status   updt
>0001         A       01/01/2002
>0002         C       01/02/2002
>0003         I       01/02/2002
>
>
>When I try a select like:
>
>
>select driver_id, status, min(updt) as updt ;
>	from temp2 ;
>	group by 1 ;
>	into cursor t1
>
>
>I get
>
>
>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.
>
>How do I get all of the fields for the earliest records?
>
>
>Thanks
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform