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?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
MSTdev
  • 4,507
  • 2
  • 23
  • 40

2 Answers2

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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
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
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • 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? – juergen d Mar 29 '14 at 14:24