The following code is supposed to find electors that do not have a postal vote, do have a telephone number are not in possession of certain codes are listed in another table called voting intentions with certain pledges or are not listed in that table at all.
FROM electors,voting_intention
WHERE
electors.telephone > 0
AND electors.postal_vote != 1
AND (
electors.mosaic NOT IN ('E1','E2','E3')
OR (
electors.ID = voting_intention.elector
AND voting_intention.pledge IN ('U','W','X')
)
OR electors.ID != voting_intention.elector
)
At the moment it is producing a count of over 2 million records many times the number in the database. Obviously something is wrong but I can’t see my error.
1 Answer