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 a category.
Assume there is record containing
my expression is,
..WHERE categories REGEXP ',?4,?'
but this returns both product of category
I just need to display only category
Am I missing something?
WHERE categories REGEXP "(^|,)4(,|$)"
4 if surrounded by commas or at the start/end of the string.
In your present version, both commas are entirely optional, so the