Reputation: 161
I have a database that I am learning SQL with and I am trying to add the string '(Deceased)' next to my pets that have passed away (meaning that a column with 'dead' has value 1. So I do:
UPDATE pet
SET name = str(name) + '(Deceased)'
WHERE dead = 1;
But it doesn't work and I am not sure why. Any help is appreciated.
Upvotes: 3
Views: 89
Reputation: 440
Use CONCAT Function:
UPDATE pet
SET name = CONCAT( name , '(Deceased)')
WHERE dead = 1;
Upvotes: 0
Reputation: 85
You don't need to specify the data type in the query ... run the below query and it will store Deceased under your name column where dead=1
UPDATE pet SET name = 'Deceased' WHERE dead = 1;
plus if there is only one row to update then I suggest you to use primary key (id)
in the where clause to change the name instead of dead
. You can do
Upvotes: 0
Reputation: 39477
You want to use concatenation operator ||
:
UPDATE pet SET name = name || '(Deceased)' WHERE dead = 1;
Upvotes: 3