Try
SELECT cCode, cDesc, dDate ;
FROM mytable mt1 ;
WHERE NOT EXISTS ( ;
SELECT * FROM mytable mt2 ;
WHERE mt2.cCode = mt1.cCode AND mt2.dDate > mt1.dDate) ;
INTO CURSOR crsResult
SELECT cCode, cDesc, dDate ;
FROM mytable mt1 ;
WHERE dDate = ( SELECT MAX(dDate) FROM mytable mt2 ;
WHERE mt2.cCode = mt1.cCode) ;
INTO CURSOR crsResult
>
>I'd appreciate a suggested SQL command for the following problem: how to get the most recent records for each subgroup in a list.
>
>Given table:
>
>
>cCode cDesc dDate
>----- ------------- ------
>AAA American 1/1/03
>AAA American Air 1/1/04*
>BBB Boeing Air 1/1/03
>BBB Boeing Inc 1/1/04
>BBB Boeing Exc 1/1/05*
>CCC Canada Air 1/1/03
>CCC Air Canada 1/1/04*
>
>
>I'd like to pull the recent records (greatest dDate) of each cCode subgroup:
>
>AAA American Air 1/1/04
>BBB Boeing Exc 1/1/05
>CCC Air Canada 1/1/04
>
>
>I'm trying to get a cursor to use looking up the most current descriptor for each code. For example, I want to know that BBB now means "Boeing Exc" and not "Boeing Air". Hopefully this can be done in a single SQL command for use in a view with SET ENGINEBEHAVIOR 90 (and the implications that has for GROUP BY). I've tried some subqueries and using Max(dDate) but can't quite get it. Any help would be appreciated.
--sb--