Re: Best way to do this query?

From: Carlos M. Calvelo <c_jackal_at_hotmail.com>
Date: 17 Jan 2007 08:26:18 -0800
Message-ID: <1169051178.273057.156680_at_s34g2000cwa.googlegroups.com>


Carlos M. Calvelo schreef:
>
> select inv.invoiceid, inv.customerid, inv.amount, max(inv.date)
> from Invoices as inv
> group by inv.invoiceid, inv.customerid, inv.amount
> having max(inv.date) = (select max(date) from Invoices where customerid
> = inv.customerid)
> order by inv.customerid
>

oops... there is no need to aggregate. it's same as:

select inv.invoiceid, inv.customerid, inv.amount, inv.date from Invoices as inv
where inv.date = (select max(date) from Invoices where customerid = inv.customerid)
order by inv.customerid

Carlos Received on Wed Jan 17 2007 - 17:26:18 CET

Original text of this message