Update field values globally

If I have two fields, fieldA and fieldB, where fieldA is populated, but fieldB is not, I know I can update fieldB globally to equal the value of fieldA, using:

UPDATE table
SET fieldA = fieldB

But how can I do the same, but add a prefix to the value of fieldB?

My use case is that fieldA contains a filename, and I would like to globally update fieldB to equal the full path to the file as well as the filename

So if fieldA = ‘my_image.jpg’ I want to globally update fieldB to equal ‘http://www.mywebsite.com/images/my_image.jpg’.


UPDATE MyUnicornTable
   SET fieldB = 'http://www.mywebsite.com/images/' || fieldA

Thank you.

Also just found:

UPDATE table
SET fieldA = CONCAT (‘http://www.mywebsite.com/images/’, fieldB)

well, yeah

tip: when you post, be sure and mention your platform

i gave you standard sql… CONCAT is weak sauce mysql

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.