Home » SQL & PL/SQL » SQL & PL/SQL » Returning the first row of a group
Returning the first row of a group [message #4216] Tue, 19 November 2002 14:26 Go to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
I have a table TAB with columns C1, C2, C3, and C4.

The select I am using is:

SELECT C1, C2, C3, Max(C4) from TAB GROUP BY C1, C2, C3.

I basically want 1 row for each set of distinct C1, C2, Max(C4) values. If there are multiple C3 values, I just want to select 1 of the rows (I don't care which one).

Can anyone tell me how to do this (We're not using Enterprise Oracle, so analytic functions aren't enabled).
Re: Returning the first row of a group [message #4217 is a reply to message #4216] Tue, 19 November 2002 14:49 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Would something like this work?

select *
  from t
 where (c1, c2, c4) in
   (select c1, c2, max(c4)
      from t
     group by c1, c2);


If not, show some sample data with the desired result set.
Previous Topic: Re: Best way to process large volume of data (Oracle9i)
Next Topic: Trigger Mutation problem (jobs Scheduling)
Goto Forum:
  


Current Time: Mon Apr 29 08:37:23 CDT 2024