sql - Updating a column in MySQL using its previous value -
this question has answer here:
- mysql string replace 4 answers
i have table in mysql 'url_map' 2 columns: id, url values populated in it. this:
+----+-----------------------------------------+ | id | url | +----+-----------------------------------------+ | 1 | http://myserver.mywebsite.com/file1.txt | | 2 | http://myserver.mywebsite.com/file2.txt | +----+-----------------------------------------+
my requirement update 'url' of every row in table new value using it's previous value.
+----+---------------------------------------------+ | id | url | +----+---------------------------------------------+ | 1 | https://mynewserver.mywebsite.com/file1.txt | | 2 | https://mynewserver.mywebsite.com/file2.txt | +----+---------------------------------------------+
if see changes, in every row, value of 'url' has been changed
- http:// https://
- myserver mynewserver
rest other things in url kept previously.
can please me out in writing query ?
you can use previous value directly in update statement
update your_table t set t.url = replace(replace(t.url, 'http://', 'https://'), 'myserver', 'mynewserver')
Comments
Post a Comment