Skip to content

Instantly share code, notes, and snippets.

@sgronblo
Created April 23, 2012 06:21
Show Gist options
  • Save sgronblo/2469091 to your computer and use it in GitHub Desktop.
Save sgronblo/2469091 to your computer and use it in GitHub Desktop.
Multi column/row update with a single query for mysql
UPDATE table
SET col1 = CASE id
WHEN id1 THEN id1_v1,
WHEN id2 THEN id2_v1
END
col2 = CASE id
WHEN id1 THEN id1_v2,
WHEN id2 THEN id2_v2
END
WHERE id IN (id1, id2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment