How do I prepend string to a field value in MySQL?

9.6k Views Asked by At

I have a huge table of products from a specific vendor with a UPC column. I need to differentiate these products' UPCs from other vendors. The current idea is to prepend all of these UPCs with the letter a.

UPDATE abc_items SET upc = 'a' + upc

is basically how I imagine doing something like this, but I know it will not work.

1

There are 1 best solutions below

0
On BEST ANSWER

Just use the CONCAT function.

CONCAT(str1,str2,...)

Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent nonbinary string form.

UPDATE abc_items SET upc = CONCAT('k', upc)