james
james

Reputation: 26271

MySQL populating a new field from parts of existing fields

I have a few fields holding paths to images. I now want to add another field holding the image name. How can I extract the file name from the full path from another field and update the name into the new field?

this is how i want it to look:

fields:

image_thumbnail | image_name

values:

http://mysite.com/images/thumbnail/1234.jpg | 1234.jpg

note: image names may have different file extensions

Upvotes: 0

Views: 116

Answers (1)

hsz
hsz

Reputation: 152294

UPDATE your_table
   SET image_name = SUBSTRING_INDEX(image_thumbnail, '/', -1)
     ;

Upvotes: 2

Related Questions