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

Home -> Community -> Usenet -> c.d.o.misc -> Re: count and first row with one query

Re: count and first row with one query

From: Rene Nyffenegger <rene.nyffenegger_at_gmx.ch>
Date: 4 Oct 2004 15:13:08 GMT
Message-ID: <slrncm2oqh.328.rene.nyffenegger@zhnt60m34.netarchitects.com>


> Hi,
>
> is it possible, to fetch the first element of an ordered sequence and the
> number of elements in the sequence in one query? More precisely, given the
> query
>
> SELECT name FROM foo WHERE ... ORDER BY name

See http://www.adp-gmbh.ch/ora/sql/examples/first_rows.html on my homepage for a discussion on this matter.

>
> can I combine
>
> SELECT name FROM foo WHERE name=MIN(name) AND ...
> SELECT count(*) FROM foo WHERE ...
>
> into one query?

Yes. Use the technique in my link and add a count(*) in the select list.   

> As an extended version, suggest that there is a 1:n relation between the
> tables bar and foo. Can I perform a join between bar and foo, that retrieves
> the rows from bar and, for any row in bar, adds the first name and the number
> of names?

Extend the example to do that.  

hth,
Rene

-- 
  Rene Nyffenegger
  http://www.adp-gmbh.ch/
Received on Mon Oct 04 2004 - 10:13:08 CDT

Original text of this message

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