I have this records:
Number
1, 2
1, 24
How to select only 2 by LIKE not 2 and 24
SELECT * FROM test WHERE number LIKE '%2%'
1, 2 // need only this record
1, 24
I have this records:
Number
1, 2
1, 24
How to select only 2 by LIKE not 2 and 24
SELECT * FROM test WHERE number LIKE '%2%'
1, 2 // need only this record
1, 24
3
Answers
find_in_set
almost does what you want, but you’ll have to remove the spaces in order to use it:You should avoiding storing unnormalized CSV data like this. That being said, if you must proceed, here is one way:
You can do it as follows :
SUBSTRING_INDEX
to split number, andTRIM
to remove any space, then we search in to parts of the number.