3

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?

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70
Mehdi Karamnejad
  • 144
  • 2
  • 11

2 Answers2

3

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

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70
0

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

velop
  • 3,102
  • 1
  • 27
  • 30