mysql check if numbers are in a comma separated list
Not the most pretty solution, but it works:
select
UID
from
YOUR_TABLE
where
find_in_set('3', cast(NUMBERS as char)) > 0
and
find_in_set('15', cast(NUMBERS as char)) > 0
Note that it's string comparison, so you may need to cast your input parameters to char as well.
You Can Try As Like Following :
SELECT * FROM table_name WHERE FIND_IN_SET('3', NUMBERS) AND FIND_IN_SET('15', NUMBERS)
Also check if this is helpful to anyone
An Extended function to eliminate the limitation of native FIND_IN_SET()
in MySQL, this new extended version FIND_IN_SET_X()
provides feature to compare one list with another list.
i.e.
mysql> SELECT FIND_IN_SET_X('x,c','a,b,c,d'); -> 3
Checkout this link for more details.
This one also works:
SELECT * FROM table WHERE 3 IN (NUMBERS) AND 15 IN (NUMBERS)
using the IN will look into a comma separated string eg. these two
WHERE banana IN ('apple', 'banana', 'coconut')
WHERE 3 IN (2,3,6,8,90)
Info found on this page: