Java Developer
Java Developer

Reputation: 1901

Mysql,add value to a column using commas

In my database, we have a column called deleteList which holds comma separated values. How can I append values to an existing record in the database?

Upvotes: 4

Views: 2318

Answers (1)

John Woo
John Woo

Reputation: 263733

you need to UPDATE the second time if you want to concatenate the values.

UPDATE tableName
SET    deleteList = CONCAT(deleteList, ',', 'NEWVALUE')
WHERE  colName = val

where

  • NEWVALUE is the value you want to add on the list
  • colName is the key that identifies the row to be updated.

Upvotes: 6

Related Questions