Page 1 of 1

mysql update add to text

Posted: Sat Feb 06, 2021 10:03 pm
by mister_v
Can you update field to add text to an existing text, or string ?

With a single SQL-query ?

Re: mysql update add to text

Posted: Sun Feb 07, 2021 7:48 am
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.