百家汽车网
您的当前位置:首页mysql find_in_set多个,MySQL find_in_set与多个搜索字符串

mysql find_in_set多个,MySQL find_in_set与多个搜索字符串

来源:百家汽车网

I find that find_in_set only search by a single string :-

find_in_set('a', 'a,b,c,d')

In the above example, 'a' is the only string used for search.

Is there any way to use find_in_set kind of functionality and search by multiple strings, like :-

find_in_set('a,b,c', 'a,b,c,d')

In the above example, I want to search by three strings 'a,b,c'.

One way I see is using OR

find_in_set('a', 'a,b,c,d') OR find_in_set('b', 'a,b,c,d') OR find_in_set('b', 'a,b,c,d')

Is there any other way than this?

解决方案

there is no native function to do it, but you can achieve your aim using following trick

WHERE CONCAT(",", `setcolumn`, ",") REGEXP ",(val1|val2|val3),"

因篇幅问题不能全部显示,请点此查看更多更全内容