Re: Best way to do this query?

From: <michael_at_preece.net>
Date: 15 Jan 2007 05:42:41 -0800
Message-ID: <1168868561.419651.174980_at_v45g2000cwv.googlegroups.com>


Marshall wrote:

> I run in to this kind of query every so often. I wonder if
> there's a canonical best way to do it?
>
> Consider the following schema:
>
> Invoices:{invoiceid, customerid, date, amount}
>
> Each invoice has an id, the id of the customer who opened the
> invoice, the date of the creation of the invoice, and the amount.
>
> If I want to know the date of every customer's most recent invoice,
> that's easy:
>
> select customerid, max(date) from Invoices group by customerid
>
> But suppose I also want to know the id and amount of that particular
> invoice?
>
>
> Marshall

Don't you mean "those particular invoices"? Suppose a Customer makes two purchases on the same day - or is that not allowed?

Mike. Received on Mon Jan 15 2007 - 14:42:41 CET

Original text of this message