comma separated argument for IN operator, MySQL

别说谁变了你拦得住时间么 提交于 2020-06-23 07:43:11

问题


I have a table in which the following query works fine:

select * 
from session_actions 
where action_type IN ('login_failed','channel_recorded')

Now I'm looking forward to some thing like the following:

select * 
from session_actions 
where action_type IN ('login_failed,channel_recorded')

As you see I want to give the IN operator one single comma separated parameter, but it is not possible

How can I convert this comma separated string into a list of parameters which is acceptable to IN operator?


回答1:


You might be looking for FIND_IN_SET() function.

select * 
from session_actions 
where find_in_set(`action_type`,'login_failed,channel_recorded');

SAMPLE FIDDLE




回答2:


I tried FIND_IN_SET but it was super slow. I rather use haystack REGEXP CONCAT('[[:<:]]', needle, '[[:>:]]') since then.



来源:https://stackoverflow.com/questions/4171832/comma-separated-argument-for-in-operator-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!