Dave [Hawk-Systems] wrote:
> have a data table that records entries by date(unix timestamp) and customer
> number. each custnum will have several entries showing a running ledger type
> snapshot. we have the need to get the most recent entry from not one, but all
> unique customers, in the most cost effective manner.
>
> [snip]
>
> Currently we are running through all our customer numbers in one query, then
> for each customer number querying the summary table to get each customers
> latest entry (select order by date desc limit 1). Obviously this results in a
> large number of queries and is expensive. Looking for a more concise, less
> expensive way.
>
> thanks
>
> Dave
What about something like:
SELECT so.* FROM summary so, (SELECT custnum, MAX(date) as date FROM
summary si GROUP BY custnum) as cd WHERE so.date = cd.date AND
so.custnum = cd.custnum
Best regards,
Arjen van der Meijden