简体   繁体   中英

How to update multiple column values in MySQL table

I want to update image path in MySQL table. Table schema is this:

table_brands - brand_id, brand_name, brand_image_path

Currently path is stored as-

`images/1.png`
`images/2.png`

I want to make it as

 `images/brands/1.png`
 `images/brands/2.png`

Also for some entries path is stored as

 `images/brands/1.png`
 `images/brands/2.png`

so changes should not be done for such entries.

Can someone help me?

You can use replace function for this purpose only for the image paths that don't contain 'brand'

 UPDATE table_brand
 SET brand_image_path = REPLACE(brand_image_path, 'images', 'images/brands')
 WHERE brand_image_path NOT LIKE '%brands%';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM