开发者

Opposite of MySQL FIND_IN_SET

开发者 https://www.devze.com 2023-03-27 02:39 出处:网络
How 开发者_开发技巧can I do the equivalent of: !FIND_IN_SET(\'needle\', haystack) 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

How 开发者_开发技巧can I do the equivalent of:

!FIND_IN_SET('needle', haystack)


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')


http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set

FIND_IN_SET('needle', haystack) = 0 should do the trick.


SELECT id FROM table where !FIND_IN_SET(needle,haystack).......

Its working for me...


It seems like it doesn't work if the field is NULL and therefore doesn't contain the value.

A workaround:

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

Hope it'll help!


Equals to 0 doesn't work, you have to use null.

SELECT id FROM table WHERE FIND_IN_SET(needle,haystack) IS NULL


  .andWhere('(NOT FIND_IN_SET(:userID, notification.deletedBy) OR notification.deletedBy IS NULL)',{userID:userId})
0

精彩评论

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