Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Update a column value, replacing part of a string

I have a table with the following columns in a MySQL database
[id, url]

And the urls are like:

 //domain1.com/images/img1.jpg


I want to update all the urls to another domain
 //domain2.com/otherfolder/img1.jpg


keeping the name of the file as is.

What's the query must I run?
by

3 Answers

akshay1995

UPDATE urls
SET url = REPLACE(url, 'domain1.com/images/', 'domain2.com/otherfolder/')
sandhya6gczb
Try using the REPLACE function:

mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
RoliMishra
Try this...

update [table_name] set [field_name] = 
replace([field_name],'[string_to_find]','[string_to_replace]');

Login / Signup to Answer the Question.