user1589800 user1589800 - 7 months ago 69
MySQL Question

mysql replace last characters in string if matched

I have a table that has some rogue tags that need replacing

The offending string ends

and needs replacing with

Not all record are affected, so I need to find these and then replace them

Our skills using Update Replace Where are limited as the characters are not unique within the string but their position is, ie the last 4 characters

Have tried using

UPDATE table
SET field
REPLACE (RIGHT(field,4),</table>)

but suspec this is over simplified (and also fails)


try this:

UPDATE table
SET field=concat(left(field,length(field) -4),'</table>')