user2772568
user2772568

Reputation: 75

Updating a column in sql



I am trying to update the data in a particular column according to the data in another column.

Some thing like below.

Name            ImageName
----------      -----------
aaa             no_image.jpg
bbb             no_image.jpg
ccc             no_image.jpg
ddd             no_image.jpg


I like to update this table something like below.

Name            ImageName
----------      -----------
aaa             aaa.jpg
bbb             bbb.jpg
ccc             ccc.jpg
ddd             ddd.jpg



Please find the sqlfiddle from the following link.

SqlFiddle Link

Upvotes: 0

Views: 44

Answers (4)

Jumabek
Jumabek

Reputation: 68

Actually i think you need to put where statement because some columns might already have image name update images t set t.image_name=t.name||'.jpg' where t.image_name='no_image.jpg'

Upvotes: 0

StanislavL
StanislavL

Reputation: 57381

update table1 set ImageName=concat(Name,substr(ImageName, instr(ImageName,'.')));

Upvotes: 2

G one
G one

Reputation: 2729

Update table1
set imagename= name+'.jpg';

Upvotes: 2

Raging Bull
Raging Bull

Reputation: 18747

You could simply do this in an UPDATE query itself.

Try this:

UPDATE table1
SET ImageName=Name+'.jpg'

Upvotes: 3

Related Questions