Re: question using aggregate function
Date: Wed, 18 Jul 2007 05:18:33 GMT
Message-ID: <Johni.4516$s25.4505_at_trndny04>
"David Cressey" <cressey73_at_verizon.net> wrote in message
news:tahni.5043$4J4.4441_at_trndny05...
>
> "Mia" <nospam_at_cox.net> wrote in message news:WC9ni.3$fK1.2@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
>
> select supplier_id, order_date
> from orders
> where order_date =
> (select max (order_date) from orders)
>
>
>
>
>
OOPS!
make that:
select distinct supplier_id, order_date
from orders
where order_date =
(select max (order_date) from orders)
(I must be slipping in my old age) Received on Wed Jul 18 2007 - 07:18:33 CEST