Skip to content

Instantly share code, notes, and snippets.

@hemantachhami19
Last active January 22, 2022 15:47
Show Gist options
  • Save hemantachhami19/f6724d5e37bcbd32cc888dbda3ad90d7 to your computer and use it in GitHub Desktop.
Save hemantachhami19/f6724d5e37bcbd32cc888dbda3ad90d7 to your computer and use it in GitHub Desktop.
-- Updating multiples ids at once
-- 1st approach
UPDATE employees
SET address = (case
when id = 1 then 'address1'
when id = 2 then 'address2'
when id = 3 then 'address3'
end)
WHERE id in (1, 2, 3);
-- 2nd approach
UPDATE employees as e
JOIN (
SELECT 1 as id, 'address1' as address
UNION ALL
SELECT 2 as id, 'address2' as address
UNION ALL
SELECT 3 as id, 'address3' as address
) as a
ON u.id = a.id SET u.address = a.address;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment