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)
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)
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);
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