开发者

mysql negation of like doesn't return what expected, why?

I have a mysql table that has 2796 entries. I'd like to select entries that doesn't contain the word SUPPR somewhere in the notes field.

If I do the 开发者_如何学Pythonfollowing

SELECT * FROM `catalogues` WHERE notes LIKE "%SUPPR%"

It returns 266 row. But if I write what I consider the complement

SELECT * FROM `catalogues` WHERE notes not LIKE "%SUPPR%"

it returns 762 rows when I was expecting 2530 (2796-266).

How should I write the second request to get what I need?


Nulls are implicitly excluded when you use NOT LIKE.
You handle separately:

SELECT * 
  FROM `catalogues` 
 WHERE (notes NOT LIKE "%SUPPR%" 
        OR notes IS NULL);

Perhaps this was only for illustrative purposes that you used it...
DBAs and performance-buffs recommend against using SELECT *.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜