Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update and append to all items in a specific column

How do I append a character to all items `purchase_id’ here is a manual example of what I want…

SELECT * 
FROM `loadable_link` 
WHERE `product_sku` = '2101-R' 
ORDER BY `customer_id` DESC

Then select from purchased_id and append a ‘0’ to all purchased ID’s

UPDATE `loadable_link` SET `purchased_id` = '11165690' 
WHERE `loadable_link`.`purchased_id` = 1116569;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can update the table according to the condition in the original select statement.

If purchase_id is a number, you can multiply it by 10:

UPDATE `loadable_link`
SET    `purchase_id` = `purchase_id` * 10
WHERE  `product_sku` = '2101-R' 

If purchase_id is a string, you can concatenate a 0 to it:

UPDATE `loadable_link`
SET    `purchase_id` = CONCAT(`purchase_id`, '0')
WHERE  `product_sku` = '2101-R' 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading