[thelist] SQL Query
Christopher Marsh
Christopher.Marsh at akqa.com
Tue Jun 8 12:06:28 CDT 2010
Jack
> I have a table of customer charges. I want to find only the latest
> paid_on for each customer. So, I did a query to order the results by
> when it was paid_on descending, and grouped by ID.
>
> Well, as you can imagine, no matter what I order in, I always get the
> most recent charge.
>
> Now, I know that doing the following query works out like I want it to:
>
> SELECT * FROM (
> SELECT *
> FROM charges
> ORDER BY paid_on DESC
> ) as temp
> GROUP BY id
Would the following satisfy your criteria?
SELECT MAX(paid_on),
id
FROM charges
GROUP BY id
HTH
--
Christopher Marsh
More information about the thelist
mailing list