Mark Harrison
Mark Harrison

Reputation: 304434

Oracle: apply multiple updates in single statement?

Suppose I have a simple update of one table with data from another table.

update t1
   set (a,b) = (select a,b from t2 where id=17)
 where id=17;

How can i apply a similar update to multiple id's in one statement? In my brain I'm thinking iteratively of something like this:

for X in (select id from t2 where ...):
    update t1
       set (a,b) = (select a,b from t2 where id=X)
     where id=X;

Generic SQL preferred, but Oracle-specific solutions welcomed as well.

Upvotes: 0

Views: 587

Answers (1)

Tony Andrews
Tony Andrews

Reputation: 132570

How about:

update t1
   set (a, b) = (select a,b from t2 where t2.id=t1.id)
 where t1.id in (select id from t2 where ...);

Upvotes: 1

Related Questions