Ambika Gupta
Ambika Gupta

Reputation: 61

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

In Mysql procedure:

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


idList="1,2,3"

It is only working for first value.

Upvotes: 5

Views: 34

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520918

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

Upvotes: 4

Related Questions