MySQL UPDATE append data into column

Robert Hoffmann picture Robert Hoffmann · Dec 24, 2012 · Viewed 55.4k times · Source

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?

Answer

Dhinakar picture Dhinakar · Dec 24, 2012

Try this Query:

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

Refer this sql fiddle demo.