Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: first row with sql?
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.