Insert space in MySQL column value I have a value like "this - is - a -comment". However I need to run an update statement to add a space after the last - (-comment above should be - comment)

Any able to help me with an update statement?
Here is one solution, there may be more efficient ways of doing it but this is one way that avoids more complicated solutions like using regular expressions.

update YourTable SET [ColumnValue] = REPLACE(REPLACE([ColumnValue],'- ', '-'), '-', '- ')


So what this is doing is setting all instances of '- ' to '-' first, in order to make the spacing between hyphens/words consistent throughout your whole string. It then takes all instances of '-' and transfers them to '- '.

The reason behind doing this double replace is to avoid adding extra spaces between the hyphen and the word.

If you just did:

update YourTable SET [ColumnValue] = REPLACE([ColumnValue], '-', '- ')


You would end up with multiple spaces between the hyphen and the words (in the case of "- is" and "- a").