Page 1 of 1

Update column including its own column info

Posted: Tue Jul 15, 2008 11:29 am
by kryles
Hi,

I remember reading this somewhere but couldn't find it again so I was hoping someone could point me in the right direction.

I want to do something simple like

Code: Select all

 
update tablename
set column1 = column1 + 'this string'
where columnkey = 106
 
instead of doing a select for the column, adding the string and then updating the new information. My hosting service uses MySQL 4.0.24 if that makes any difference in SQL version.

column1 is empty by default but is a varchar type

Regards,

Re: Update column including its own column info

Posted: Tue Jul 15, 2008 8:56 pm
by Benjamin

Code: Select all

 
UPDATE tablename
  SET column1 = CONCAT(column1, 'this string')
WHERE
columnkey = 106
 

Re: Update column including its own column info

Posted: Wed Jul 16, 2008 7:17 am
by kryles
Thanks astions :D

My example seemed to not be working when the field was empty, but when it wasn't the + worked fine. Just thought I'd mention that in case someone comes across this thread for future reference