merge masterid how to get expected result

how to get expected result

contactid Active merged Masterid 69084F59 Y N NULL BB63BE1A N Y 69084F59 136560 N Y BB63BE1A

datsset

expected Result

Expected Result

contactid Active merged Masterid 69084F59 Y N NULL BB63BE1A N Y 69084F59 136560 N Y 69084F59