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.
相关问题
- How to get the maximum of more than 2 numbers in V
- Faster loop: foreach vs some (performance of jsper
- sqlyog export query result as csv
- Convert Array to custom object list c#
- pick a random item from a javascript array
SELECT COUNT(*) FROM my_table WHERE (my_column LIKE '%,0,%' OR my_column LIKE '%,1,%');
or
SELECT COUNT(*) FROM my_table WHERE (my_column REGEXP LIKE '.*,[0-1],.*');
Do you mean
It will work but very bad because of performance. There is also another way
but the best way is to change data structure if possible.
I would use a solution like this:
this will make the following string:
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.