1

I have a a column item_id_list with comma separated id such as this:

enter image description here

I can search them by using FIND_IN_SET() such as this:

SELECT * FROM task_detail WHERE FIND_IN_SET('21', item_id_list)

but I need to check whether multiple id did exist in the row but adding another id to search will not work as stated in the docs.

https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set

This function does not work properly if the first argument contains a comma (,) character.

SELECT * FROM task_detail WHERE FIND_IN_SET('21, 79', item_id_list)

Without changing my table structure, how do I solve this problem? Right now looping FIND_IN_SET() by number of id is the solution.

sg552
  • 1,521
  • 6
  • 32
  • 59

1 Answers1

3

You could use a OR with find_in_set

    SELECT * FROM task_detail 
    WHERE FIND_IN_SET('21', item_id_list)
    OR  FIND_IN_SET('79', item_id_list)
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107