mysql : UPDATE table and CONCAT data

Syntax : UPDATE and CONCAT(first,second)

table name : jos_data
+------+------+------------+
| id   | name | images     |
+------+------+------------+
|    1 | John | jonh.jpg   |
|    2 | Ram  | rem.jpg    |
|    6 | Jack | jek.jpg    |
|    9 | Joke | jok.jgp    |
+------+------+------------+

situation 1: 
I want to prefix all data in "images" column to look like "/path/to/img/file.jpg"

solution 1: 
UPDATE jos_data SET images = CONCAT('/path/to/img/', images) WHERE id IN (1,2,6,9);


situation 2:
I want to prefix all data in "images" column to look like "file.jpg--noext"

solution 2:
UPDATE jos_data SET images = CONCAT(images, '--noext') WHERE id IN (1,2,6,9);

done.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s