Hello!
I'm trying to update two fields of several rows at once but I can't determine the right syntax to do so, except for doing so with one field update.
Each row is identified by an id, and therefore I'm using a CASE statement.
I have this table:
tbl_accounts(id_account, nation_id, group_id)
Now, the following query works for updating only one field:
UPDATE tbl_accounts SET nation_id = CASE id_account
WHEN 3 THEN 333
WHEN 5 THEN 555
ELSE nation_id END
The above will update the nation_id field of each corresponding row identified by its id_account.
And the following query doesn't work for updating two fields - please suggest a fix to the syntax. I'm trying to avoid using any SELECT/JOIN/etc':
UPDATE tbl_accounts SET nation_id = CASE id_account, group_id = CASE id_account
WHEN 3 THEN 3331, 3332
WHEN 5 THEN 5551, 5552
ELSE nation_id, group_id END
I could run this as two separate statements but I'm sure there's a way to combine the two into one.
Any help is highly appriciated!