Reputation: 101
Is it possible to update by id other row values?
I try like this But nothig..
UPDATE era
SET id = CASE
WHEN id = 3 THEN gender = 'Female'--or maybe it is possible to call insert command here? insert into era (gender) values 'female'?
WHEN id = 4 THEN gender = 'Male'
END;
I would kike to have values changed in my table in the result...
Upvotes: 1
Views: 127
Reputation: 164154
If you want to update the column gender
then you should use it in SET
instead of id
like this:
UPDATE era
SET gender = CASE id
WHEN 3 THEN 'Female'
WHEN 4 THEN 'Male'
END
WHERE id IN (3, 4)
Upvotes: 1
Reputation: 3316
I am not aware how big your update is but It is possible using the table in from
clause join and then slight change to the case
statement as,
update era u
set gender = case
when f.id = 3
then 'Female'
when f.id = 4
then 'Male'
end
from era f
where u.id = f.id
Upvotes: 1