Basically I want to check whether a mysql text column, which contains comma-separated values, contains any of the values contained in an array. I know this can be done with a loop and multiple queries, but I was hoping for a single query. Is this possible? Thank you.
解决方案
I would use a solution like this:
SELECT
*
FROM
yourtable
WHERE
str RLIKE
CONCAT('[[:<: replace>:]]|[[:<:>:]]')
this will make the following string:
'values,in,the,array'
like this:
[[:<:>:]]|[[:<:>:]]|[[:<:>:]]|[[:<:>:]]
[[:<: and>:]] are word boundaries so it will match only whole words, and | is an OR so it will match any of the words. Please see fiddle here.