Where statement with multiple 'Not Like'
If "field" is not just single words, you would need to do something like this:
SELECT * FROM table WHERE field LIKE '%Pandora%' AND field NOT LIKE '%radio%' AND field NOT LIKE '%internet%' and field NOT LIKE '%digital%';
First of all, your query is redundant, in that if field
is LIKE
'pandora'
, then the other conditions will by default return false.
There is no possible way that field
can be equal to 'Pandora'
, 'radio'
, 'digital'
, and 'internet'
.
As a result, you can simplify your query using the following example:
SELECT * FROM example WHERE field = 'Pandora';
If the two conditions represent two separate fields, then you can use the REGEXP
operator to enforce the DRY principle while still allowing for further pattern matching:
SELECT * FROM example WHERE field_1 = 'Pandora' AND field_2 NOT REGEXP '^(radio|digital|internet)$';
If you're searching for specific words, you can use NOT IN()
WHERE field LIKE 'Pandora' AND field NOT IN('radio', 'digital', 'internet');
If you need the wildcard %
in your search you'll need to use multiple LIKE
s.