Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql find/replace string in fields

Tags:

People also ask

How can I replace part of a string in a column in SQL?

SQL Server REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive.

How do I change a column value in MySQL?

To replace, use the REPLACE() MySQL function. Since you need to update the table for this, use the UPDATE() function with the SET clause.


I have a table which has a few varchar fields named like this:

image_fullres | image_highres | image_mediumres | image_lowres | image_thumbnail

I currently have the same value for each of these fields(differing by row), so image_fullres has the same path as image_lowres and so on.

an example value for these paths would be http://mysite.com/images/image1.jpg

I would like to have each of these fields to contain a different and appropriate path name, so:

  • image_fullres has value of http://mysite.com/images/fullres/image1.jpg
  • image_highres has value of http://mysite.com/images/highres/image1.jpg
  • image_mediumres has value of http://mysite.com/images/mediumres/image1.jpg

and so on...

Since all of my data is already in the database with duplicate paths by row, what SQL can I execute that would change the value of each field's data to an appropriate path?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!