Make sure you have indexes on proper fields. But I suspect that the problem
has to do with qryTempeAccounts having to run multiple times. Perhaps
that can be optimized in the subquery. Also, if qryTempeAccounts has an
ORDER BY clause drop it.
Suggest you post the code for qryTempeAccounts in addition to what you
already have posted. Wild guess that the subquery might end up looking
something LIKE the following
In (SELECT TOP 20 AccountID
FROM Sometable as T
WHERE T.Marketplace = qryTmpeAccounts.Marketplace
GROUP BY AccountID
ORDER BY Sum(Amount) DESC)
SUM(Amount)
> Hello I have following SQL:
> SELECT qryTempeAccounts.*
[quoted text clipped - 12 lines]
>
> thank you!
Hi,
You have an index on marketPlace and on [Total Over 60] ? Probably not,
since you call the table "qryTempeAccount", which is, I suppose, a query.
Make a temporary table out of the query, and index the mentioned fields.
If this it still too slow, try to join (to compute a rank) rather than to
"sub-query":
SELECT a.marketPlace, a.totalOver60
FROM myTable As a LEFT JOIN myTable as b
ON a.marketPlace = b.marketPlace AND a.totalOver60 < b.totalOver60
GROUP BY a.marketPlace, a.totalOver60
HAVING COUNT(b.totalOver60) < 10
In that query, COUNT(b.totalOver60) supplies the rank, within the same
marketPlace, occupied by the value a.totalOver60. I use a LEFT join and
strict < comparisons to include all the ex-equo that could eventually fill
position 10.
Hoping it may help,
Vanderghast, Access MVP
> Hello I have following SQL:
> SELECT qryTempeAccounts.*
[quoted text clipped - 12 lines]
>
> thank you!
GEORGIA - 17 Nov 2005 16:00 GMT
Thank you both!!
It runs so much quicker! !
> Hi,
>
[quoted text clipped - 35 lines]
> >
> > thank you!