14

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.

TRiG
  • 10,148
  • 7
  • 57
  • 107
ma77c
  • 1,052
  • 14
  • 31
  • 4
    upc = CONCAT('k',upc) – Roy Bogado Aug 30 '17 at 14:25
  • Maybe this would be a good time to look at normalizing your database. – Dan Bracuk Aug 30 '17 at 14:34
  • I'm not sure what you are trying to do exactly as there is no `WHERE` condition for example, but adding a column / re-thinking your database design would seem a better idea than prefixing values. – jeroen Aug 30 '17 at 14:35
  • @jeroen | This table contains products from a single vendor. We have many vendors that sell us the same products, with the same UPCs. This solution is so we can differentiate which vendor a specific product came from. Anyways, I'm just a dev :/ ... – ma77c Aug 30 '17 at 14:48
  • Possible duplicate of [How to prepend a string to a column value in MySQL?](https://stackoverflow.com/questions/680801/how-to-prepend-a-string-to-a-column-value-in-mysql) – Burgi Nov 09 '18 at 15:36

1 Answers1

27

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)
Community
  • 1
  • 1
Neodan
  • 5,154
  • 2
  • 27
  • 38