Opposite of MySQL FIND_IN_SET

2019-02-11 23:58发布

How can I do the equivalent of:

!FIND_IN_SET('needle', haystack)

4条回答
倾城 Initia
2楼-- · 2019-02-12 00:11

It seems to do not work if the field is NULL and therefore doesn't contain the value.

So I wrote the following workaround:

WHERE id NOT IN (SELECT id FROM table WHERE FIND_IN_SET(needle,haystack))

Hope it'll help!

查看更多
【Aperson】
3楼-- · 2019-02-12 00:15

FIND_IN_SET returns the index of the match if it is found, and returns 0 if it is not found. Since 0 is FALSE you can just use NOT FIND_IN_SET('needle', 'haystack')

查看更多
ゆ 、 Hurt°
4楼-- · 2019-02-12 00:32
疯言疯语
5楼-- · 2019-02-12 00:34
SELECT id FROM table where !FIND_IN_SET(needle,haystack).......

Its working for me...

查看更多
登录 后发表回答