Your query is taking so much time as there are many
AND
conditions.
And the main problem is
not in()
function which generally takes more time.
You should avoid that.
Instead of
not in
, try to
INNER JOIN[
^] the tables to fetch the data faster.
I am not using MS-Access. So, I am not sure whether the following query will work or not.
But I tried to optimize the query. Take a look.
SELECT DISTINCT (a.customer)
FROM
customermaster as a
INNER JOIN
PMRegister as b
ON a.customer = b.customer
AND a.active = 'T'
AND a.sectorName = 'Jayanagar'
AND MONTH(dt) >= MONTH(cdate(11/12/2012))
AND YEAR(dt) <= YEAR(cdate(1/12/2012))
AND YEAR(dt) >= YEAR(cdate(11/12/2012)))
ORDER BY a.Customer
I may be wrong. Please try to implement
INNER JOIN
and eliminate the extra conditions as far as possible.
Thanks...