Link to home
Start Free TrialLog in
Avatar of renisenbb
renisenbb

asked on

SQL: Want to update multiple rows in one statement

Let's say i have 3 rows:
id    year
--    --------
10    1980
11     1981
12     1992
I want to update these rows so that it is :
10    1970
11     1901
12     1980
So i want to update ids 10,11,12 with the year 1970,1901,1980   RESPECTIVELY.
How would i do this in DB2?
Avatar of Naitik Gamit
Naitik Gamit
Flag of India image

try like,

Update Year_Master(your table) set year=
 case
     when id = 10 then 1970
     when id = 11 then 1901
     when id = 12 then 1980
  end
     WHERE id  in (10,11,12)
ASKER CERTIFIED SOLUTION
Avatar of renisenbb
renisenbb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of renisenbb
renisenbb

ASKER

It worked.