second version of merging after removing duplicate rows