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 -> count and first row with one query

count and first row with one query

From: Jochen Wiedmann <jochen.wiedmann_at_freenet.de>
Date: 4 Oct 2004 06:42:32 -0700
Message-ID: <c66df65e.0410040542.3f0c12c0@posting.google.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

can I combine

    SELECT name FROM foo WHERE name=MIN(name) AND ...     SELECT count(*) FROM foo WHERE ...

into one query?

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?

Regards,

Jochen Received on Mon Oct 04 2004 - 08:42:32 CDT

Original text of this message

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