Re: How to limit number of rows SELECTed?
Posted in 1997
Hi Jamwal,
first, what are the first 20 rows ? Do you mean the first
20 rows physically or the first 20 rows inserted in your table ?
A Jamwal wrote:
>
> Hi everyone,
> Is it possible to limit the number of rows
> returned by a SELECT statement? For example:
>
> SELECT * FROM items
Of course, there is a way to select only the first 20 rows.
This will not work with "dbaccess", but with every programming
language.
Whenever you want to read a set of rows, you must use a CURSOR.
Simply fetch only the first 20 rows; there is no need to read
the remaining rows.
DECLARE XXX CURSOR FOR SELECT * FROM ITEMS;
OPEN XXX,
for ( i = 0; i < 20; i++ )
FETCH xxx INTO :hostrecord;
CLOSE XXX;
If you want to do the same with "dbaccess", I think there's a
way to get the same result, if you would use a Stored Procedure.
> The above statement returns all the rows from the
> items table. However, I want to select only, say,
> the first 20 rows. How do I restrict the number of
> rows SELECTed? In Oracle, one can use rowsnum like:
>
> SELECT * FROM items
> WHERE rownum < 21>
> Is there something similar in Informix?
Bye
Stefan
PS: I don't think that it's a good idea to use the *rowid*.