mysql update add to text

Post Reply
mister_v
Posts: 170
Joined: Thu Mar 04, 2010 9:19 pm

mysql update add to text

Post by mister_v »

Can you update field to add text to an existing text, or string ?

With a single SQL-query ?
chris
Site Admin
Posts: 172
Joined: Mon Jul 21, 2008 9:52 am

Re: mysql update add to text

Post by chris »

you can use concat to add to already existing string (varchar,text,...)

Code: Select all

UPDATE table_name SET text_field=CONCAT(text_field,'string to add') WHERE  id='1';
It doesn't work if the value is NULL,
It works with an empty string ('').
So you should replace all NULL values with empty string before.
Post Reply