The MERGE statement basically works as separate insert, update, and delete statements all within the same statement. You specify a “Source” record set and a “Target” table, and the join between the two.
MERGE INTO table_name AS T //Target table
USING table_name2 AS S //Source table
ON T.column_name = S.column_name
WHEN MATCHED THEN
//statement to run when match found in target
WHEN NOT MATCHED THEN
//statement to run when no match found in target