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 -> Re: Very simple SQL question ... or maybe not

Re: Very simple SQL question ... or maybe not

From: Valery Yourinsky <vsu_at_bill.mts.ru>
Date: Wed, 04 Apr 2001 08:51:18 +0400
Message-ID: <3ACAA846.DD8FF774@bill.mts.ru>

Mike Moore wrote:
>
> Given my_table and data:
>
> col_a col_b col_c
> A 7 cat
> A 2 dog
> B 4 zebra
> B 8 buraq
>
> the output should be
>
> A 7 cat
> B 8 buraq
>
> in other words... For each unique col_a, select the largest col_b and it's
> related col_c.
>
> I can do it this like
>
> select col_a, max(col_b||' '||col_c) from my_table group by col_a;
>

   SELECT * FROM my_table
   WHERE (col_a, col_b) IN

      (SELECT col_a, MAX(col_b)
       FROM my_table
       GROUP BY col_a)

Valery Yourinsky

-- 
Oracle8 Certified DBA
Moscow, Russia
Received on Tue Apr 03 2001 - 23:51:18 CDT

Original text of this message

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