Update MySQL table with prepended/appended strings on a field

The following code is how you would mass-update a single field in a MySQL table with a string prepended and appended to the field’s existing value.

UPDATE `table` SET `field` = CONCAT('prepend',`field`,'append') WHERE 1

We used this method update all the records in an osCommerce store to point to images (uploaded via FTP) that were named after the product’s model number. The code we used is displayed below.

UPDATE `products` SET `products_image` = CONCAT('products/',products_model,'.jpg') WHERE 1

I hope this helps some of you MySQL users out there. If all else fails, read the DOCs :)

Bookmark and Share

One thought on “Update MySQL table with prepended/appended strings on a field

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>