Reputation: 31160
I have table called 'system' has 2 columns 'variable' and 'value' with the following data:
I want to update these 2 fields in 1 query.
the 2 queries are:
UPDATE System SET Value = 'myuser' WHERE Variable = 'Username'
UPDATE System SET Value = 'mypass' WHERE Variable = 'Password'
Upvotes: 1
Views: 209
Reputation: 23
UPDATE System SET `Value` = IF(`Variable`='Username', 'myuser', 'mypassw')
WHERE `Value` IN ('Username', 'Password');
Upvotes: 0
Reputation: 433
UPDATE System SET
Value = (case Variable when 'Username' then 'myuser' when 'Password' then 'mypass' end)
WHERE Variable = 'Username' or Variable = 'Password'
Upvotes: 0
Reputation: 1270021
Yes, using he case statement:
UPDATE System
SET Value = (case when Variable = 'UserName' then 'myuser'
when Variable = 'Password' then 'mypass'
else Value
end)
WHERE Variable in ('Username', 'Password');
Upvotes: 2
Reputation: 204794
UPDATE System
SET Value = case when Variable = 'Username' then 'myuser'
when Variable = 'Password' then 'mypass'
end
WHERE Variable in ('Username', 'Password')
Upvotes: 0
Reputation: 8109
UPDATE System
SET Value = (CASE
WHEN Variable = 'Username' THEN 'myuser'
WHEN Variable = 'Password' THEN 'mypass'
END)
WHERE Variable = 'Username' or Variable = 'Password'
Upvotes: 4