Last active
January 22, 2022 15:47
-
-
Save hemantachhami19/f6724d5e37bcbd32cc888dbda3ad90d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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