Ame
Ame

Reputation: 163

special update mysql like .= php operator

Is there a way in MYSQL to UPDATE a column in a table adding some new text at the end of the current one?

For example I have in my table a field named "names". I just want to add some new names at the end of this field.

So before the update the names field is :"name1,name2,"

and I'm adding the new text: "name3,name4".

Is there a way to directly UPDATE this table without extracting data for saving the field names with "name1,name2,name3,name4,"?

In php I would directly do it with the .= operator.

Upvotes: 0

Views: 52

Answers (1)

micropro.cz
micropro.cz

Reputation: 616

You can use CONCAT() function like this:

UPDATE table SET column = CONCAT(column, 'new-value');

Of course you can also prepend (and even append):

UPDATE table SET column = CONCAT('prepend this', column, 'new-value');

Or join multiple columns to one.

Upvotes: 1

Related Questions