开发者

How to write a DML to update a field in a table based on a field of another table?

Suppose there are two tables 'A' and 'B'. A ( F1 number, F2 number ) and B ( F1 number, F2 number ). I want a dml to do this :-

All rows where A.F1 = B.F1, set A.F2 = B.F2.

(i.e.)

开发者_如何学JAVA

if A : [(1,34)(2,67)] B : [(1,99)(2,100)]

DML should update A to following:

A : [(1,99)(2,100)]

Thanks in advance !

Trinity


It sounds like you just need a correlated update

UPDATE a
   SET f2 = (SELECT f2
               FROM b
              WHERE a.f1 = b.f1)
 WHERE EXISTS (
    SELECT 1
      FROM b
     WHERE a.f1 = b.f1 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜