Pretty straightforward question: Why the output of the following SQL is not null?
SELECT * FROM table WHERE
(`FirstName` LIKE 'D%' OR `LastName` LIKE 'D%' OR `City` LIKE 'D%')
AND
(`FirstName` NOT LIKE 'D%' OR `LastName` NOT LIKE 'D%' OR `City` NOT LIKE 'D%')
I am using MySQL 5.1. The result is ignoring the “NOT LIKE” part all together.
If you have a
FirstNamethat of ‘David” then the first parenthetical condition is true. If you have aLastNameof “Smith” then the second parenthetical condition is true and your query will return that result.What you probably mean to be doing is something like this:
(Note the
ORs that have been changed toANDs.)