注意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);