I have a table with key/value columns. I need to update a key/value pair based on another value's condition.
Table:
--------------------------
| id | key | value |
--------------------------
| 1 | country | canada |
| 2 | privacy | default |
--------------------------
In this case I need to change value
to canada
where key = privacy
only IF country = canada
.
I've tried something like this:
UPDATE settings
SET value =
CASE
WHEN key = 'country' AND value = 'canada' THEN 'canada'
ELSE value
END
WHERE key = 'privacy'
but it results in an error on the CASE
condition. I think I might need to do some sort of sub-query?