szymon_dybczak
Esteemed Contributor III

Hi @Puneet096 ,

One approach you can use is merge into statement. Probably you can delete update part from below merge template, because it's unlikely that there will be update of values in composite primary key

 

 

MERGE INTO target_table AS target
USING source_table AS source
ON target.pk1 = source.pk1 AND target.pk2 = source.pk2
WHEN MATCHED AND source.last_updated > target.last_updated THEN
  UPDATE SET
    target.data = source.data,
    target.last_updated = source.last_updated
WHEN NOT MATCHED THEN
  INSERT (pk1, pk2, data, last_updated)
  VALUES (source.pk1, source.pk2, source.data, source.last_updated);