Re: SQL question (retriveing n number of rows)
Posted in 1996
Toby Denbow <toby@mathworks.com> wrote: :How do I retrieve a set number of rows in a SQL select. :If my select is something like: :select * from tab1 where x = y. :how do I retrieve only the first 50 rows. Is this the third most asked question? Is it in the FAQ? You can't if you use only sql. There is no statement to set the max number of rows returned or any other (easy) way to do it. (I don't know of a hard way either.) In a programming language you can however easily define a cursor and fetch only the first 50 rows. Be aware however that if you do it wrong the whole result set will be generated in a temporary table before you start to retrieve any rows. One case where this may happen is if you do an order by that can't use an index. A simple statement like the one in you example (from one table and no order by) will never generate the whole resultset first. It will allways read the rows directly from the table as you do your fetchs. Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org