简体   繁体   中英

AND NOT LIKE doesn't work

How can I check for not like <<something>> in mysql?

I've tried the following, but the result is always empty: http://sqlfiddle.com/#!2/29a97/1

SELECT * 
FROM convertList 
WHERE server='1' and converting not like '%1%' 
ORDER BY important DESC

also tried:

SELECT * 
FROM   convertlist 
WHERE  server = '1' 
       AND NOT converting LIKE '%1%' 
ORDER  BY important DESC 

ps

the list is 100% not empty, I should have at least 10 results.

在此处输入图片说明在此处输入图片说明

I'm using percona mysql 5.6.

This works fine: http://sqlfiddle.com/#!2/f44790/1

Maybe your simplification of the query masks the problem.

Edit: so I was ALMOST right, your simplification of the DATA was the problem... you have NULLs:

SELECT * FROM convertList WHERE server='1' 
and ( converting not like '%1%' OR converting IS NULL)
ORDER BY important 

NULL is not like any value, and it's not UNlike any value.... it the the lack of a value.

Here is an update SQLfiddle working with NULLs and 1s, thanks to @Orlo http://sqlfiddle.com/#!2/628e0/1

试一试

not converting like '1'

field not like '1' is basically the same as field != 1 ... maybe field not like '%1%' ? (field does not contain "1") ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM