Search code examples
sqlwildcardsql-likemultiple-conditions

Error when using 2 (NOT LIKE) wildcards


I can't seem to figure out why my code isn't printing out the right information.

SELECT FirstName FROM Customer WHERE FirstName NOT LIKE "P%" OR FirstName NOT LIKE "T%";

The table will not show any names starting on P or T if I remove one of the conditions (P or T), and the table will only show the names starting with P or T if I change "NOT LIKE" to just "LIKE" on both. But the moment I use two "NOT LIKE" conditions it shows ALL the names, and neither of my NOT LIKE conditions will execute.


Solution

  • You need to use an AND instead of an OR. Not like P or Not like T will always be true for everything; because one of the statements will always be true. You want them both to be true, so need an AND.