My table had \'tags\' field like this:
tag1,tag2,tag3
How to remove \',tag2\' including comma using mysql query.
Apart from the first answer which I didn't test and therefore I have no opinion about, the others would fail in the below cases:
1- tags = "tag1,tag2,tag22,tag3"
2- tags = "tag2,tag1,tag3"
in the first example, the REPLACE(tags, 'tag2', '') function will remove the third comma separted value i.e. tag22 as well, and in the second example tag2 will not be replaced by REPLACE(tags, ',tag2', '')
one possible solution can be:
REPLACE(REPLACE(CONCAT(',', tags, ','), 'tag2', ''), ',,', ',')
the problem with my solution is that you will always ending up with having values stores with redundant commas both at the start and the end of string. but in my case it works well.