Skip to content
Advertisement

How to update row by id using case?

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…

Advertisement

Answer

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)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement