Problem:
I have a table like this :
A | B
-----------------------------------------
1 | 5,25,24,22,21,6,19,18,17,15,13,11
2 | 25,15,17,4,33,12,34,40,24,5,1,26,43,9
3 | 25,15,11,36,29
I need to select rows where my number is in column B.
try:
I use RegEx for this. I write this code :
SELECT *
FROM `table`
WHERE `B` REGEXP "([^\d]|^)MYNUMBER[^\d]
and RLIKE
([^\d]|^)MYNUMBER[^\d] : ([^\d]|^) : not number or be a first char. MYNUMBER [^\d] : not number
When MYNUMBER is 25 or 34 or any double digit number, I haven't got any problem.
But when MYNUMBER is 5 or 1 or any one digit number, it's trouble.
Result example1:
input: MYNUMBER : 24
result:
A | B
-----------------------------------------
1 | 5,25,24,22,21,6,19,18,17,15,13,11
It's okay.
Result example2:
input: MYNUMBER : 5
result:
A | B
-----------------------------------------
1 | 5,25,24,22,21,6,19,18,17,15,13,11
2 | 25,15,17,4,33,12,34,40,24,5,1,26,43,9
3 | 25,15,11,36,29
Wrong answer, row 3 is wrong.
It is strange:
I tried my expression in regexr.com and it's true.
find_in_set()? dev.mysql.com/doc/refman/5.0/en/…FIND_IN_SET(), or add commas to the beginning and end of the string you're searching, and what you're searching for. e.g. search for string,5,withinCONCAT(',',t.B,',')