Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: count and first row with one query
> 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
![]() |
![]() |