set1 id1 id2 id3 1 1 3 2 2 2 3 3 3 set2 id1 id2 id3 1 2 2 1 2 3 1 2 4 the resulting union should be id1 id2 id3 1 1 3 1 2 3 2 2 2 3 3 3 the groups are via id1 i.e. consider the group from set1 and set2 with id1=1 then look at each observation in set2 such that set1.id3 <= set2.id3 left join all matches in set2 to the resulting dataset I only care about the next one if any (>=) observation in set2. i.e. set2 should be ordered by id1, id2, then id3. The resulting set should only contain the lowest (1st of) observation (via id3) in set2 that has a matching id1 in set1. As you can see 1 2 4 Isn’t in the result Since we already had 1 2 3 From set2 and 3 is less than 4.
... View more