Replace Single Word or String in MYSQL

Someone asked me this one today on IM right before they were about to write a php script for it.

“How do you replace a single word/substring in a given field of a table?”

Here is how it’s done:

UPDATE theTable SET theField = REPLACE(theField, "replace me", "with something else");

Easy enough, no reason to write nasty php to loop through each row etc…


Leave a Reply

Spam protection by WP Captcha-Free