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