Let say I have something like this:
id | title |
1 | First row |
Now I want to update that value to be: First row is here, by just adding is here. And as you think, there is more than one row, and I want to update all the rows dynamically.
UPDATE posts SET title=title+' is here'
I know that the above is wrong, I just thought that since it works with numbers, maybe it will also with text, but it doesn't.
use concat
:
UPDATE posts SET title=concat(title,'your_string_to_add') WHERE id='your_id'
It is important to give WHERE id = 'id'
otherwise it will update the first row I beleive. In your case:
UPDATE posts SET title=concat(title,' is here') WHERE id=1
To do that you need to concatenate strings, MySQL has the function CONCAT(), so your query would be:
UPDATE posts SET title=CONCAT(title,' is here')
UPDATE posts SET title=CONCAT(title,' is here')