What is use of Merge in SQL?
Merge statement is a powerful feature that allow us to perform insert, update and delete operations in a single operation based on a condition.
It is particularly useful for synchronizing data between tables or performing upsert operations.(update if exists, insert if not exists)
Syntax:
MERGE INTO target_table AS targetUSING source_table AS sourceON merge_conditionWHEN MATCHED THEN UPDATE SET column1 = value1, column2 = value2, …WHEN NOT MATCHED BY TARGET THEN INSERT (column1, column2, …) VALUES (value1, value2, …)WHEN NOT MATCHED BY SOURCE THEN DELETE;
perform INSERT , UPDATE or DELETE rows in one query using