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

Home -> Community -> Usenet -> c.d.o.server -> Q: Avoiding group by on selected fields

Q: Avoiding group by on selected fields

From: Ivan Bajon <ib_at_ed.dk>
Date: Wed, 19 Aug 1998 16:56:07 +0200
Message-ID: <6reor1$7j8$1@news1.tele.dk>


I'm having problems formulating a group by statement. I'd like to stay clear of subqueries in this particular case - if so possible. I have a table:

a_table:

    Field1,
    A_DATE_FIELD,
    Field2

, and I wish to select rows in the following manner:

All the rows, grouped by Field1, which has the maximum A_DATE_FIELD within each group - no matter the contents of Field2 - but I need Field2 as well for those rows satisfying the forementioned criteria.

If I issue:

select

    Field1,
    max(A_DATE_FIELD),
    Field2,
from a_table
group by Field1

I get an error. If instead I issue:

select

    Field1,
    max(A_DATE_FIELD),
    Field2,
from a_table
group by Field1, Field2

I get too many rows because it groups the different valued Field2's as well. That's exactly what I'm trying to avoid. Is there a way to formulate this in SQL without the use of subqueries?

Thanks to those who replied to my previous questions. I really hope you'll help me out this time too.

Received on Wed Aug 19 1998 - 09:56:07 CDT

Original text of this message

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