Search code examples
mysqlappendsql-update

MySQL UPDATE append data into column


I need to UPDATE tablename (col1name)

If there is already data, I need to append it with values 'a,b,c' If it is NULL, I need to add the values 'a,b,c'

I know there is a CONCAT argument, but not sure what the SQL syntax would be.

update tablename set col1name = concat(ifnull(col1name, 'a,b,c'), 'a,b,c')

Is the above correct?


Solution

  • Try this Query:

    update tablename set col1name = concat(ifnull(col1name,""), 'a,b,c');
    

    Refer this sql fiddle demo.