I have a table with the following columns in a MySQL database
[id, url]
And the urls are like:
http://domain1.com/images/img1.jpg
I want to update all the urls to another domain
http://domain2.com/otherfolder/img1.jpg
keeping the name of the file as is.
What's the query must I run?
SQL Server REPLACE() FunctionThe REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive. Tip: Also look at the STUFF() function.
UPDATE urls SET url = REPLACE(url, 'domain1.com/images/', 'domain2.com/otherfolder/')
UPDATE yourtable SET url = REPLACE(url, 'http://domain1.com/images/', 'http://domain2.com/otherfolder/') WHERE url LIKE ('http://domain1.com/images/%');
relevant docs: http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With