SELECT fields FROM table ORDER BY uniqKey, isProduction DESC, version DESCand some sample data looks like
Uniq_Key isProd Version K1 1 1 <---- K2 0 3 <---- K2 0 2 K2 0 1 K3 1 3 <---- K3 0 2 K3 0 1 K4 1 2 <---- K4 0 3 K4 0 1Note K4 shows a newer version but the production flag has not been set.
Uniq_Key Version K1 1 K2 3 K3 3 K4 2Maybe I'm having a super-senior day but I can't come up with anything better than
SELECT uniq_key,version,RECNO() as recno FROM myCursor INTO CURSOR tmp1 SELECT uniq_key,min(recno) as recno FROM rlp1 GROUP BY uniq_key INTO CURSOR tmp2 SELECT tmp1.* from tmp1 JOIN tmp2 ON tmp1.uniq_key = tmp2.uniq_key AND tmp1.recno = tmp2.recno INTO CURSOR tmp3I don't want to rely on RECNO() (although I think it's safe in a single table select).