Replace part of string in mysql table column Replace part of string in mysql table column wordpress wordpress

Replace part of string in mysql table column


UPDATE sometable SET somefield=REPLACE(somefield,'/wordpress//','/wordpress/');

Edit

@Kevin asked me to explain this query, so here we go:

  • I assume the basic UPDATE is clear: In all rows of sometable assign a new value to somefield
  • the REPLACE() function does exactly what it says: It replaces text. In our use case we ant it to take the old value of somefield, then replace all ocurrencies of '/wordpress//' with '/wordpress/'
  • these two parts taken together mean, in all rows of sometable assign somefield the value, that results, if you replace all ocurrencies of '/wordpress//' with '/wordpress/' in the old value.