根据条件用一个表的字段,去更新另一个表的字段
注意ON关联值不能重复。
SELECT A.A1,A.A2,B.B1,B2 FROM TABLEA A LEFT JOIN TABLEB B ON A.A1 = B.B1 WHERE A.A2 IS NULL AND B.B2 IS NOT NULL ------------------------------------ MERGE INTO TABLEA A USING TABLEB B ON (A.A1 = B.B1 ) WHEN MATCHED AND A.A2 IS NULL AND B.B2 IS NOT NULL THEN UPDATE SET A.A2=B.B2 --这个比UPDATE的好处就是只全表扫描一次,还可以一次性做多个操作,如UPDATE,INSTER,DELETE --WHEN NOT MATCHED THEN --INSERT....
数据量少的情况下,容易理解的
UPDATE A a SET(A1) = (SELECT b.B1 FROM B b where a.ID=b.ID) WHERE EXISTS (SELECT 1 FROM B b WHERE a.ID = b.ID);
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/archive/2012/10/09/2717227.html