> DATE CLT_CODE
>1996.01.01 FFF
>1998.01.01 FFF
>1999.01.01 FFF
>2000.02.24 FFF
>
>1997.01.01 BBB
>2000.02.22 BBB
>
>1999.12.31 AA
>2000.10.01 AA
>
>You see the oldest account is the first oldest reference for each client.SELECT 000000 AS clt_order, ; MIN(date) AS firstdate, ; clt_code AS ccode ; FROM invoice ; INTO TABLE inv_temp1 ; GROUP BY 3 ; ORDER BY 2 * at this point you have a table with oldest invoice * for each customer, sorted by date (the table name * really should be a unique name that will not conflict * with any other user) * make the order usable in the next SQL SELECT SELECT inv_temp1 REPLACE ALL clt_order WITH RECNO() * now do the final select SELECT date, clt_code ; FROM invoice ; INNER JOIN inv_temp1 ON clt_code = ccode ; ORDER BY temp1.clt_order, dateNot very elegant, but it does the job. Others may have a simpler way, but I can't think of it.