1

I have a field that contains a string values like this: '1,2,3,4'

I want to bring it if contains the number 2,4. But its not working. I have try this:

SELECT field IN (2,4)

and this:

select find_in_set('2,4', field)
Diogo
  • 11
  • 1
  • 1
    Now you see why putting comma delimited data in a MySQL cell is such a bad idea and breaks all sorts of Normalisation rules – RiggsFolly Jun 24 '20 at 15:19

2 Answers2

1

As find_in_set() will only find one string within another, you will have to use many find_in_set searches. Also this is because if you have 1,2,3,4 but want to find 1 and 3 or 1 and 4 you cannot make a finder string to do that.

So to find 1 and 3 in 1,2,3,4 use

SELECT * FROM <table>
where find_in_set('1', COL)
AND find_in_set('3', COL);
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

This may help you.

WHERE banana IN ('apple', 'banana', 'coconut')
WHERE 3 IN (2,3,6,8,90)

source : mysql check if numbers are in a comma separated list

Krishan Kumar
  • 394
  • 4
  • 13