I need to "add" data to a field that already contains data without erasing whats currently there. For example if the field contains HTML, I need to add additional HTML to the field. Is there a SQL call that will do this or do I need to call the data in that field, concatenate the new data to the existing data, and reload it into the database?
Asked
Active
Viewed 3.6k times
4 Answers
12
UPDATE myTable SET html=concat(html,'<b>More HTML</b>') WHERE id='10'
... for example. Your WHERE would be different of course.

Jeff B
- 29,943
- 7
- 61
- 90
4
Append at the end of a field, separated with with a line break:
UPDATE Table SET Comment = CONCAT_WS(CHAR(10 USING UTF8), Comment, 'my comment.');
CONCAT_WS()
appends multiple strings separated by a given separator.CHAR(10, UTF8)
is a line break.

powtac
- 40,542
- 28
- 115
- 170
4
UPDATE Table SET Field=CONCAT(IFNULL(Field, ''), 'Your extra HTML')
If the field contains NULL value then CONCAT will also return NULL. Using IFNULL will help you to update column even it has NULL value.

Urvish
- 126
- 4
-
This instruction appends to all rows. If you want to append only in one specific row add this at the end of the expression: `WHERE your_row = $your_var`. – statosdotcom Jun 22 '22 at 01:25