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: Matt Brennan <mbrennan_at_gers.antispam.com>
Date: Fri, 05 Jun 1998 23:56:11 GMT
Message-ID: <01bd90dd$7f5215a0$049a0580@mcb>


How about a union:

select count(*), ' ' from T where ...
group by ' '
union
select ... from T where .. AND rownum <= 10

Just remember to keep the number of select-list expressions the same between each part of the union by using dummy columns as necessary. Might also have to play with column heading and aliases to keep things appearing neatly, too.

--
Matt Brennan
SQL*Tools Specialist
GERS Retail Systems
9725-C Scranton Road
San Diego, California 92121
1-800-854-2263
mbrennan_at_gers.com
(Original email address is spam-blocked.)

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
>
Received on Fri Jun 05 1998 - 18:56:11 CDT

Original text of this message

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