Description
The MERGE INTO syntax in Spark allows two types of WHEN clause:
- WHEN MATCHED: Specify optional condition and actions (delete or update) to apply to rows that satisfy the merge condition.
- WHEN NOT MATCHED: Specify optional condition and actions (insert) to apply toi rows from the source table that don't satisfy the match condition.
Other products also offer a third type of WHEN clause:
- WHEN NOT MATCHED BY SOURCE: Specify optional condition and actions (delete or update) to apply to rows from the target table that don't satisfy the merge condition.
See for example T-SQL Merge Documentation
Example:
MERGE INTO target USING source ON target.key = source.key WHEN MATCHED THEN UPDATE SET * WHEN NOT MATCHED THEN INSERT * WHEN NOT MATCHED BY SOURCE THEN DELETE