Subject Re: FIRST m SKIP n problem
Author Ed Dressel
> I have a table that contains several records per person per day, as:
> name,datetime,blabla
> joe,2003-10.31-08.00,test1
> joe,2003-10.31-09.00,test2
> joe,2003-10.31-10.00,test3
> joe,2003-10.31-11.00,test4
> joe,2003-10.31-12.00,test5
> etc
>
> I want to retrieve the last 4 things joe has done, ordered by
> datetime (asc).

I believe the quickest way would be to write a stored procedure that
returns the number of records you want, something like (I didn't test
this and am sure it needs some tweaking);

create procedure ReturnActivities(PersonID integer; NumRecords
integer)
returns...
as
declare variable CurrCount integer;
declare variable ...
begin
CurrCount = 0;

for select <fields>
from <table>
where Person_ID = :PersonID
order by DateTimeField
into <variables>
do begin
suspend;
CurrCount = CurrCount + 1;
if (CurrCount > NumRecords) then exit;
end;
end;

Using this mehtod the database would only have to get the set of
records once.

Ed Dressel

end;