tags:

views:

41

answers:

1

I want to update a column by adding a new value alongside the old ones. So if column "fruits" has a value of "apples" and I run my query it should then have a value of "apples, oranges".

Right now when I do an update statement"

UPDATE tableName SET fruits='oranges' WHERE id=1;

It just overwrites apples with oranges. How can I get it to ADD the new value alongside the old separated by commas?

+1  A: 
UPDATE tableName SET fruits=CONCAT(fruits, ', oranges') WHERE id=1;

or:

UPDATE tableName SET fruits=CONCAT_WS(', ', fruits, 'oranges') WHERE id=1;
ceejayoz
This won't do what he wants if `fruits` is empty.
SLaks
True, but it sounds like there are existing values from the post.
ceejayoz