Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Reducing hte number of SQL statements

Re: Reducing hte number of SQL statements

From: Gert Rijs <nospampleasegem_at_wirehub.nl>
Date: 5 Jun 1998 10:19:55 GMT
Message-ID: <01bd9054$729b87d0$0100007f@gertrijs>


[posted & mailed]

Senthil Kumar <skumar_at_scotch.cs.mci.com> wrote in article <slrn46nen8r.hat.skumar_at_scotch.mcit.com>...
> Assume there is some table T.
> For some select criteria, I only want
> the first 10 rows, however, I also want
> to find out the number of rows that match the
> select criteria.
>
> Is it possible to do this in one
> SQL statement?
>
> I know how to do this in 2 SQL statements.
>
> 1. select count(*) from T where ...
> 2. select ... from T where .. AND rownum <= 10
>
> thanks,
> Senthil
>

Hi,
the following query will return 10 rows with the total number of rows as the first column

select t1.numrow, t2.*
from (select count(*) as numrow from T where ...) t1, T t2 where .... and rownum <= 10

hth,
gert
--
reply address is altered to keep the spam down remove the nospamplease part to reply... Gert Rijs
gem at wirehub.nl
www.wirehub.nl/~gem Received on Fri Jun 05 1998 - 05:19:55 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US