use table1 in 0 alias A use table2 in 0 alias B select A go top scan cCode = A.Code select top 10 B.Code, B.Date, B.nPrice ; from Table2 B ; where B.Code = cCode ; order by b.Date Desc ; into cursor cTmp01 ; then i calculate the average like this; select a.code, avg(a.nPrice) as nAvgPrc ; from cTmp01 A ; order by a.code ; group by a.code ; into cursor cTmp02 endscanAs you can see i have to loop 80 times or so to achieve this.