There are lots of great ways to do this depending on the specifics, how big are the files, will you be doing this by hand as a one time quick fix or programmatically, how does ONE indicate the proper record in TWO, how easy is the latest date to identify?
* LASTREC will be storing a recno(), 8 allows for 10M possible TWO records
CREATE TABLE ONE (KEY C(8),LASTREC C(8)) && KEY UNIQUE
* Since you are adding records over time, I'll assume that the lowermost record is the latest dated record you want
CREATE TABLE TWO (KEY C(8),DT D) && KEY NOT UNIQUE
CLOS DATA
* I don't see why you want to do this with all ONE.records but here goes
USE ONE
INDEX ON KEY UNIQUE TAG KU
SET ORDER TO KU
SELE 0
USE TWO
SET RELA TO KEY INTO K1
*TWO is in unsorted order so the lowest record is the one to keep
*Also, since I am using the relation backwards as many-to-1, I do not use SET SKIP
REPL FOR NOT EOF("ONE") ONE.LASTREC WITH RECNO()
* Notice that ONE.LASTREC will be overwritten many times with only the LAST-LOWEST aka the latest date one being preserved. Whether or not this is too sloppy depends on how big your files are and how often this is done.
USE
SELE ONE
DELE TAG ALL
CLOSE
If you can't depend on the order of the files and SQL appeals to you, a simple select can obtain the recno() of the greatest DT. Examine the SUBSTR part carefully to see how a MAX() can be assembled and shredded to provide exactly and only what we want. FOX SELECT does not provide the HAVING MAX(...) function extension so we must duplicate it from what is provided.
USE ONE
FL=LEN(LASTREC) && You can't include LEN(LASTREC) in the SELECT statement without generating an unintentional JOIN. You can use a memory variable though.
USE
SELE KEY,SUBSTR(MAX(DTOC(DT,1)+STR(RECNO(),FL)),9) AS MAXREC FROM TWO GROUP BY KEY INTO CURSOR TWOMAX
* FOX does not always handle RECNO() correctly during SELECT..GROUP BY. Check carefully and switch to a real field if necessary
INDEX ON KEY UNIQUE TAG KU
SELE 0
USE ONE
SET RELA TO KEY INTO TWOMAX
REPL ALL LASTREC WITH IIF(NOT EOF("TWOMAX"),VAL(TWOMAX.MAXREC),0)
*LASTREC gets 0 if there are no entries in TWO
CLOS DATA