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

Home -> Community -> Usenet -> comp.databases.theory -> Re: question using aggregate function

Re: question using aggregate function

From: David Portas <REMOVE_BEFORE_REPLYING_dportas_at_acm.org>
Date: Tue, 17 Jul 2007 21:56:02 +0100
Message-ID: <97KdnVQSgOFDsQDbnZ2dnUVZ8sCsnZ2d@giganews.com>


"Mia" <nospam_at_cox.net> wrote in message news:WC9ni.3$fK1.2_at_newsfe12.phx...
> I'm having trouble with a query concept.
>
> I know that:
>
> select max(order_date) from orders;
>
> will return the date of the newest order, and that:
>
> select supplier_id, max(order_date) from orders group by supplier_id;
>
> returns the newest order date from each supplier. But I'm trying to write
> a query that would return only the supplier_id of the most recently placed
> order. How would I do that? I thought maybe:
>
> select supplier_id, max(order_date) from orders group by supplier_id
> having max(order_date) = order_date;
>
> but it complains that order_date isn't a group by expression in the having
> clause.
>
> Any ideas how to do this?
>
> -Mia

Have you thought about using a correlated subquery?

-- 
David Portas 
Received on Tue Jul 17 2007 - 15:56:02 CDT

Original text of this message

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