Search code examples
mysqlsqlfind-in-set

comma separated argument for IN operator, MySQL


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?


Solution

  • 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