The following examples fail because they reference a table other than the source or target table in either their ON, WHEN MATCHED, or WHEN NOT MATCHED clauses.
The following example fails because table t4 is neither the derived source table s nor the target table t1.
MERGE INTO t1 USING (SELECT x2,y2, z3 FROM t2, t3 WHERE y2=10) AS s ON x1=y2 AND t4.x4=z2 WHEN MATCHED THEN UPDATE SET z1=10 WHEN NOT MATCHED THEN SELECT (y2, z2, x2);
The following example fails because table t3 is neither the derived source table s nor the target table t1. Even though t3 is specified in the USING source table subquery, it violates the restriction that only source and target tables can be referenced in an ON clause.
MERGE INTO t1 USING (SELECT x2,y2, z3 FROM t2, t3 WHERE y2=10) AS s ON x1=y2 AND t3.x4=z2 WHEN MATCHED THEN UPDATE SET z1=10 WHEN NOT MATCHED THEN INSERT (y2, z2, x2);