Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql comma seperated string not working for in where in(myArray) by using procedure?

Tags:

In Mysql procedure:

select  distinct org_fk from user where id
in(IdList);


idList="1,2,3"

It is only working for first value.

like image 653
Ambika Gupta Avatar asked Mar 21 '18 06:03

Ambika Gupta


1 Answers

You can't use the IN operator to compare against a CSV string, only a CSV list of separate values.

But MySQL has a function FIND_IN_SET which might help here:

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

You may read more about FIND_IN_SET here.

Stack overflow Link

like image 176
Tim Biegeleisen Avatar answered Sep 22 '22 13:09

Tim Biegeleisen