Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql not like does not work

I have a problem with mysql select using "not like" in where conditions. There are 15k records in table. 3k records are with value 'test' in column col1.

This select works fine:

select 
    *
from
    `table`
where
    `col1` like 'test'

3000 rows selected. This is correct.

But if I try this select:

select
   *
from
   `table`
where
   `col1` not like 'test'

0 rows selected while I expect 12000 rows.

I will be grateful for any ideas?

like image 980
sajushko Avatar asked Dec 19 '22 19:12

sajushko


1 Answers

So I solved it. Problem was in data, not in request. I didn't realize that not like condition doesn't work for NULL value.

http://sqlfiddle.com/#!2/17270/2

like image 66
sajushko Avatar answered Jan 13 '23 21:01

sajushko