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.)
开发者_如何学JAVAif 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 );
精彩评论