>The TOP clause must have GROUP BY. Which I added in the subquery but it still gives me an error.
I believe that is misinformation. I've never used it that way.
Looks like you will have to create a user-defined function to solve your problem until VFP9 gets here.
select KEYFIELD, CUST_ID, ORD_DATE, ORD_TIME ;
from ORDERTABLE ;
where KEYFIELD == GetLatestOrderKey(CUST_ID) ;
order by CUSTOMER
procedure GetLatestOrderKey
lparameter tcCUST_ID
local array laKeys[1]
select top 1 KEYFIELD from ORDERTABLE ;
where CUST_ID == tcCUST_ID ;
order by ORD_DATE, ORD_TIME descending ;
into array laKeys
return laKeys[1]
I tested this.
>Thank you for your help.
Always glad to pay back for all the good help I get here.
Peter
Peter Robinson ** Rodes Design ** Virginia