Limiting number of rows in answer set

Limiting number of rows in answer set

Post by Frank C. Garbe » Fri, 08 Sep 2000 09:38:10



Is there a way to limit the number of rows returned from a select
statement???

Please respond to my email address as well, I don't always have access
to
the news group.

Thanks,

Frank Garber

 
 
 

Limiting number of rows in answer set

Post by Frank C. Garbe » Fri, 08 Sep 2000 09:44:35


Is there a way to limit the number of rows returned from a select
statement???

Please respond to my email address as well, I don't always have access
to
the news group.

Thanks,

Frank Garber


 
 
 

Limiting number of rows in answer set

Post by bernd hohman » Fri, 08 Sep 2000 17:30:37



> Is there a way to limit the number of rows returned from
> a select statement???

see faq.

bernd

--
class Mandel{public static void main(String a[]){float b,e,r,n,d;int h;
for(e=1.1f;e>-1.2;e-=.1){for(b=-2;b<1;b+=.04){r=n=0;for(h=127;r*r+n*n<4
&&--h>32;){d=r;r=r*r-n*n+b;n=2*d*n+e;}System.out.write(b>0.98?10:h);}}}}

 
 
 

Limiting number of rows in answer set

Post by Frank C. Garbe » Fri, 08 Sep 2000 18:58:20


Bernd,

Where can I find the faq?  It doesn't appear in the subject of any of
the postings...


Thanks,

Frank



> > Is there a way to limit the number of rows returned from
> > a select statement???

> see faq.

> bernd

> --
> class Mandel{public static void main(String a[]){float b,e,r,n,d;int h;
> for(e=1.1f;e>-1.2;e-=.1){for(b=-2;b<1;b+=.04){r=n=0;for(h=127;r*r+n*n<4
> &&--h>32;){d=r;r=r*r-n*n+b;n=2*d*n+e;}System.out.write(b>0.98?10:h);}}}}

 
 
 

Limiting number of rows in answer set

Post by Serge Riela » Sat, 09 Sep 2000 00:13:51


Bernd: your footnote seems to be broken...
Frank:
use the FETCH FIRST <n> ROWS ONLY clause in a select statement.
In nested selects you can use rownumber()

Cheers
Serge

--
Visit the DB2 UDB and DB2 Connect Online Support site at:
http://www.ibm.com/software/data/db2/udb/winos2unix/support

 
 
 

Limiting number of rows in answer set

Post by Dorie Perfett » Sat, 09 Sep 2000 00:46:59


You can try a combination of a fetch-first clause and/or an order-by
clause and/or an optimize-for clause. The fetch-first will select the
first N rows in the result set for the statement. This is documented in
the SQL reference.

> Is there a way to limit the number of rows returned from a select
> statement???

> Please respond to my email address as well, I don't always have access
> to
> the news group.

> Thanks,

> Frank Garber


 
 
 

Limiting number of rows in answer set

Post by fred blogg » Wed, 13 Sep 2000 08:14:29


In os/390 v5 optimize will only indicate to the optimizer that you expect
this number of
rows to be returned and db2 will select the optimum access path for that
number of rows.  If the result set exceeds that number performance can be
degraded.  Try the following correlated subselect (also not madly performant
but it works):

select col1, col2, col3 from table1 t1
where 10 > (select count(*) from table1 t2
                      where t1.col1 < t2.col1)

Change the value of 10 to however many rows you want back!



> Is there a way to limit the number of rows returned from a select
> statement???

> Please respond to my email address as well, I don't always have access
> to
> the news group.

> Thanks,

> Frank Garber