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?
You can append data to a MySQL database field with the help of in-built CONCAT() function. Here is the query to append the data ”Taylor” to the data already in the column. Therefore, the data will get appended.
To prepend a string to a column value in MySQL, we can use the function CONCAT. The CONCAT function can be used with UPDATE statement.
Try this Query:
update tablename set col1name = concat(ifnull(col1name,""), 'a,b,c');
Refer this sql fiddle demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With