Question

Do you know the method to change a part of a link in a field in a sql table?

Example:

mydomain.ltd/image10.png 

to

newdomain.ltd/image10.png 

This query will delete all the link!

UPDATE users SET avatar = 'newdomain' WHERE avatar like '%mydomain%' 
Was it helpful?

Solution

you need REPLACE .

Try that:

   UPDATE users SET avatar  = REPLACE(avatar, 'www.xxx.com', 'www.yyy.fr')
   WHERE avatar like '%www.xxx.com%'

this will replace just the word mydomain to newdomain.

  mydomain.ltd/image10.png

to

  newdomain.ltd/image10.png
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top