Search code examples
mysqlsqlstringsql-update

MySql - Way to update portion of a string?


I'm looking for a way to update just a portion of a string via MySQL query.

For example, if I have 10 records all containing string as part of the field value, is there a way to change string to anothervalue for each row via one query?

I.e. for the following:

Change something/string, something/stringlookhere, something/string/etcetera to something/anothervalue, something/anothervaluelookhere, something/string/etcetera


Solution

  • I think this should work:

    UPDATE table
    SET field = REPLACE(field, 'string', 'anothervalue')
    WHERE field LIKE '%string%';