With what I would think are reasonable table and field names, this won't
work unless you include a subquery. On the other hand, with what I think
are reasonable table and field names to match, Dale's doesn't work for me,
either.
It's trivially easy to do with two queries, a totals query that calculates
the SumOfSales grouped by ClientID, and a query with the tblClients joined
to that totals query. Both Queries were built in the Query Builder and their
SQL is:
The final query:
SELECT tblClients.ClientID, tblClients.ClientName,
qrySalesByClient.SumOfSales
FROM tblClients LEFT JOIN qrySalesByClient ON tblClients.ClientID =
qrySalesByClient.ClientID
ORDER BY qrySalesByClient.SumOfSales DESC;
qrySalesByClient:
SELECT tblSales.ClientID, Sum(tblSales.Sales) AS SumOfSales
FROM tblSales
GROUP BY tblSales.ClientID;
And, because predicting timing is not all that accurate, I would hesitate to
waste time creating just one set of SQL with a subquery until I decided that
the query was running long enough that such an approach might pay back the
time and effort.
If "many" is less than "several tens of" in your prediction, you may just
never be able to improve on the simplest approach.
Larry Linson
Microsoft Office Access MVP