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: Alan <alan_at_erols.com>
Date: Mon, 4 Oct 2004 15:26:07 -0400
Message-ID: <2sdmeeF1katr6U1@uni-berlin.de>

"Rene Nyffenegger" <rene.nyffenegger_at_gmx.ch> wrote in message news:slrncm2oqh.328.rene.nyffenegger_at_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/

Renee,

I don't recall seeing your name as a regular here, but please be aware that there are many students posting homeowrk assignments here looking for easy answers. As a custom, we do not answer these questions directly, but try to offer help and hints _only_ if the person also posts some of his own work to demonstrate that he as attempted a solution.

It is sometimes hard to tell when a question is a homework problem in disguise, but we tend to error towards thinking it is homework if it is something that does not look like a real-world problem, or is very simple, or uses often-used-in-homweork types of situations.

This one smells like homework. Received on Mon Oct 04 2004 - 14:26:07 CDT

Original text of this message

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