Appending data to a MySQL database field that already has data in it

后端 未结 4 1809
一向
一向 2020-12-04 23:45

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

相关标签:
4条回答
  • 2020-12-05 00:36
    UPDATE Table SET Field=CONCAT(Field,'your extra html');
    
    0 讨论(0)
  • 2020-12-05 00:37
    UPDATE myTable SET html=concat(html,'<b>More HTML</b>') WHERE id='10' 
    

    ... for example. Your WHERE would be different of course.

    0 讨论(0)
  • 2020-12-05 00:43

    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.
    0 讨论(0)
  • 2020-12-05 00:47

    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.

    0 讨论(0)
提交回复
热议问题