Re: SQL question (retriveing n number of rows)
Posted in 1996
Barry Johnson — — source: Informix-list mailing list archive (1991-1998)
>If my select is something like:
>select * from tab1 where x = y.>
>how do I retrieve only the first 50 rows.
>
>-Toby Denbow
>tdenbow@mathworks.com
Toby,
A possible solution could be to load the first fifty rows into a defined array
(see code below).
Within the foreach below you could process the records as well as checking for
the 50th record.
define counter integer
define fa_table array[50] record like tabl.*
declare c1 cursor for
select *
from tabl
where x = y
let counter = 1
foreach c1 into fa_tabl[counter].*
let counter = counter + 1
if counter >= 50 then
exit foreach
end if
end foreach
Barry Johnson
bjohnson@csi.wr.com.au