How to replicate a SAS merge
I have two tables, t1 and t2: t1 person | visit | code1 | type1 1 1 50 50 1 1 50 50 1 2 75 50 t2 person | visit | code2 | type2 1 1 50 50 1 1 50 50 1 1 50 50 When SAS runs the following code: DATA t3; MERGE t1 t2; BY person visit; RUN; It generates the following dataset: person | visit | code1 | type1 | code2 | type2 1 1 50 50 50 50 1 1 50 50 50 50 1 1 50 50 50 50 1 2 75 50 I want to replicate this process in SQL, and my idea was to use a full-outer-join. This works unless there are duplicate rows. When we have duplicate rows like in the above example, a full outer join produces the following