Which is the best way to update a mysql SET field, to remove a specific value from the field.
Eg. field categories with values: 1,2,3,4,5? I want to remove '2' from the list:
UPDATE table
SET categories = REPLACE(categories, ',2,', ',')
WHERE field LIKE '%,2,%';
But what if '2' is the first or the last value from the list?
UPDATE table
SET categories = REPLACE(categories, '2,', '')
WHERE field LIKE '2,%';
UPDATE table
SET categories = REPLACE(categories, ',2', '')
WHERE field LIKE ',2%';
How could I handle all 3 cases with one single query?!