I have looked at this question which addresses updating multiple records in one query.
The general solution is
UPDATE table_name
SET field_to_update = CASE table_key
WHEN key_value1 THEN field_value1
WHEN key_value2 THEN feild_value2
ELSE feild_to_update
END
WHERE table_key IN(key_value1 , key_value2);
My question is who can this be adapted to cater for a composite key. Say if I have columns
(id_1, id_2, column_to_update)
where id_1 and id_2 form a composite primary key.
My problem is made simpler by the fact that one of the id columns will be constant for a particular query.
For example, I need something along the lines of
UPDATE table_name
SET field_to_update = CASE (key1, key2)
WHEN (1,1) THEN field_value1
WHEN (2,1) THEN feild_value2
ELSE feild_to_update
END
WHERE (key1, key2) IN ( (1, 1) , (2, 1) );
Can anyone help please?
CASE
;CASE WHEN [condition] THEN [blah] WHEN [condition2] THEN [blah2] .... ELSE .... END
. – Disconnection