sajushko sajushko - 5 months ago 9
MySQL Question

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?

Answer

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