Skip to main content
Merges records from a source table or query into a target table. When a record in the source matches one in the target (based on the ON condition), the target record can be updated; when there is no match, a new record can be inserted. At least one of the WHEN MATCHED or WHEN NOT MATCHED clauses must be specified.
MERGE INTO Syntax
The USING clause specifies the source of the data to merge, which can be either a table or a SELECT statement. The ON clause specifies the condition(s) used to determine whether a source record matches a target record. The WHEN MATCHED clause specifies the UPDATE to apply to matching target records. The WHEN NOT MATCHED clause specifies the INSERT to apply for source records that have no match in the target table. For example, to merge a source table into a target table, updating existing records and inserting new ones:
MERGE INTO Example