I have a table named table and one of the rows in table has a value like this: 6,7,8,9
I want to select this row and this is the code I expect to work:
SELECT * FROM table WHERE 8 IN (column)
It doesn’t work. However the code which works confuses me:
SELECT * FROM table WHERE 6 IN (column)
I tried with several values and found out that only the first element of the list is working.
How can this be?
Because you are comparing number with string.
6,7,8,9cast to number will be6, so it will be true when do6 IN (column).You need to use
FIND_IN_SETfunction: