kakuki
kakuki

Reputation: 587

mysql update field without to select first

I would like to update a field but previously entered contents should be kept. Is there a way to this with one query without to select first the content.

example I have a field by name protocol what is having entries exmpl.

  1. > this is a prevoius entry

than on update should look like

  1. > this is a prevoius entry
  2. > this is a newer entry

instead of this a better workaround

SELECT protocol FROM my_table WHERE id = 1
 than I should add the new entry to my field and make the update

UPDATE my_table
SET protocol=new value
WHERE id=1 

Upvotes: 1

Views: 124

Answers (1)

soulmerge
soulmerge

Reputation: 75704

I suppose you want to concatenate the existing and the new string. The function is called CONCAT in MySQL:

UPDATE MyTable SET protocol = CONCAT(protocol, "\n", "new entry");

Upvotes: 2

Related Questions