What causing this query to execute long time. Is sub query block creating a mess?
x
SELECT WD.IdentityUserID, WD.Email, AD.mail
FROM WD INNER JOIN AD ON WD.IdentityUserID = AD.GGDComputerUserId
WHERE (((AD.mail) Not In (SELECT EMAIL FROM WD)));
Advertisement
Answer
I believe that the problem is that for every record of the INNER JOIN you are looping over all the records of the WD table.
SELECT WD.IdentityUserID, WD.Email, AD.mail
FROM WD
INNER JOIN AD ON WD.IdentityUserID = AD.GGDComputerUserId
WHERE NOT EXISTS(SELECT EMAIL FROM WD WHERE EMAIL = AD.mail);