Mysql comma seperated string not working in where in (myArray) using procedure?

In the Mysql procedure:

select distinct org_fk from user where id in(IdList); idList="1,2,3" 

It only works for the first value.

+5
source share
1 answer

You cannot use the IN operator to compare with a CSV string, but only for a CSV list of individual values.

But MySQL has a FIND_IN_SET function that can help here:

 SELECT DISTINCT org_fk FROM user WHERE FIND_IN_SET(id, idList) > 0; 

Read more about FIND_IN_SET here .

Stack overflow link

+4
source

Source: https://habr.com/ru/post/1275985/


All Articles