Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Reducing hte number of SQL statements
In article <slrn46nen8r.hat.skumar_at_scotch.mcit.com>,
skumar_at_scotch.cs.mci.com (Senthil Kumar) wrote:
>
> 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
>
count(*) is group function and return one value so usually it is used
in group queries. If you want count(*) be replicated with every row
from the second query above you can try
SELECT a.a ,b.*
FROM (SELECT count(*) a FROM t WHERE ...) a,
(SELECT * FROM T WHERE ... AND ROWNUM <= 10) b;
Yours
Alexandre
-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Fri Jun 05 1998 - 08:28:10 CDT