1

Im not sure if this is possible and I'm not finding documentation on it so I thought I would ask the experts.

Is there a way in a MySQL query to add to the existing contents of a column. For example say I have the following table:

table

id     name     value
1      Bob      red

I would like to use a query to add more to the value column while preserving the value that is already there. So for example:

UPDATE `yable` SET `value` += ',blue' WHERE `id` = 1;

Would update the row to the following:

table

id     name     value
1      Bob      red,blue

Is this possible or do I need to use a different language (like PHP) to concatenate the string before updating?

4

1 回答 1

2
UPDATE `yable` SET `value`= `value` + ',blue' WHERE `id` = 1;

是另一种写法。

+= 

是一种简短的写法。

你也有功能CONCAT()

UPDATE `yable` SET `value`= CONCAT(value,',blue') WHERE `id` = 1;
于 2013-04-29T20:47:05.020 回答