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

Home -> Community -> Usenet -> c.d.o.tools -> Re: first row with sql?

Re: first row with sql?

From: <catherine_devlin_at_purpleturtle.com>
Date: 5 Apr 2001 17:37:18 GMT
Message-ID: <9aiage$uhj$1@news.netmar.com>

In article <3AC35688.4D21BDC6_at_ratp.fr>, gg200492 <gg200492_at_ratp.fr> writes:
>
>With MSaccess there is a 'Group by' function FIRST which select only
>the first row of each group like SUM,AVG etc...
>
>how to do that with Oracle SQL?
>

I think you'll have to use the MIN function. Something like

select species,

       name
from animals
where RowID
in
  ( select min(RowID)
    from animals
    group by species
  )

I'm not sure if RowID "A" < RowID "B" really means that row A comes before B in the table. (Anybody know?) Using the RowNum pseudo-column instead doesn't seem to work, at least the way I wrote it, because the query and subquery each have their own RowNum scheme. Do you really want the first record as it appears in the table, or do you just want a representative record, or do you want first as sorted by some criterion? If the latter, just use that criterion in your MIN.

Received on Thu Apr 05 2001 - 12:37:18 CDT

Original text of this message

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