I have a product table which contains a field called \'categories\' to save product related category ids as comma separated values. I am using regexp to search products from
Use
WHERE categories REGEXP "(^|,)4(,|$)"
This matches 4 if surrounded by commas or at the start/end of the string.
4
In your present version, both commas are entirely optional, so the 4 in 24 matches.
24