Re: Top 50 Query
Posted in 1998
I've always selected out the data based on my criteria and inserted that
data into a temporary table in the order that I desire. Then I can select
out the top number of rows wanted based on the ROWID in the temporary table.
select * from table1
where age < 100
order by age desc
into temp table2;
select * from table2
where rowid <= 50;
This will return the 50 oldest persons of all rows with people less than 100
years of age.
Nick Leporacci
Raj Goel wrote in message ...
> This sounds like a FAQ but the one at iiug.org didn't have it...
>
> I have a 11000+ record table and I need to select the TOP 50 and
>the BOTTOM 50 based on an arbitrary field in the table.
>
> I.e., select the 50 most expensive stocks or 50 users with the
> least amount owed.
>
> In other systems, I'd use the LIMIT operator but Informix does not
>honor the LIMIT keyword.
>
> Suggestions, code, URLs appreciated.
>
> Thanks.
>
>
>========= << raj >> == http://www.brainlink.com/~frostbit/ ==============
> SYSADMIN: BrainLINK System (718) 805-6559 // http://www.brainlink.com
>
> You want to be president? Yes.
> Put your hand on the book and say "I Do." I Do.
> Fine, done. Let's eat. - G'Kar & Sheridan
>===========================================================================
=
>