Jawaban pertama (dan paling jelas) adalah membersihkan data sehingga Anda tidak memiliki duplikat. Sepertinya data sampel yang Anda berikan adalah hasil dari bug.
Adapun merge
pernyataan, jika data benar-benar murni digandakan, Anda bisa menggunakan distinct
:
MERGE INTO maintable pr
USING (SELECT DISTINCT contract,
membertype,
address1,
city,
state,
zipcode,
countrycode
FROM incrementaltable pra
WHERE pra.membertype = 'Parent')
ON (pr.contract = pra.contract)
WHEN MATCHED THEN
UPDATE SET pr.address1 = pra.address1,
pr.city = pra.city,
pr.state = pra.sate,
pr.zipcode = pra.zipcode,
pr.countrycode = pra.countrycode
WHERE address1 IS NULL AND pr.membertype <> 'Parent'