What is the difference between merge and upsert (union all/not exists) to load newer data?

Viewed 19

Upsert example:

SELECT
    id,
    name,
    age
FROM
    TableA

UNION ALL

SELECT
    id,
    name,
    age
FROM
    TableB As b
WHERE
    NOT EXISTS
    (
        SELECT *
        FROM TableA As a
        WHERE a.id = b.id
    )
;

Similarly we can write MERGE and use the WHEN MATCHED and WHEN NOT MATCHED to do the insert/update.

What is difference between upsert approach using union all/non exists vs merge to load new data?

0 Answers
Related