0

In my function I used IN key word with where I have one parameter value

e.g.:

CASE- 1
 '1,8,9' or

CASE- 2
 '9,8,7,4,5'   or

CASE- 3
 '9,8' 

now I get pass first '1,8,9' then result set Comes basis on only 1 ,

same as second case '9,8,7,4,5' then result set comes basis on only 9 ,

I think 'where' condition with 'IN' keyword consider only first ID

Now my question is what should I do for comma separated to rows values?

2 Answers 2

3

The replacement for in when things are stored in a list is find_in_set():

where find_in_set(col, '1,2,3') > 0

Note that this cannot take advantage of an index, so it is not recommended on larger tables. You should put the list into the SQL, either as an in or as a subquery, to make use of indexes.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to give the IN() clause seperate values and not a single one that has a list in it. This would work:

where some_column in ('9','8','7','4','5' )

In MySQL you can use the FIELD() function instead:

where field(some_column, '9,8,7,4,5') > 0

1 Comment

Please be more specific. What did you try, what error do you get and what output do ou expect? Can you add that to your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.