I am trying to sort data from two tables that pairs the closes date from table 1 with the closest date from table 2 (if exists). There may be ID-dates from table 1 that do not have a match in table 2 and vice versa. Is not guaranteed to be a 1:1 match either. For for instance my data from t1 would be something like:
ID time1
A 01/09/2015
A 02/16/2015
B 03/03/2015
C 04/01/2015
C 01/20/2015
C 03/15/2015
t2 similarly:
ID time2
A 01/29/2015
A 02/19/2015
B 03/06/2015
C 01/27/2015
C 03/18/2015
C 04/04/2015
What I don't want when joining on ID is a combination of all unique dates, rather combinations where the days between are minimum eg.
desired_output:
ID date_time1 date_time2
A 01/09/2015 01/29/2015
A 02/16/2015 02/19/2015
B 03/03/2015 03/06/2015
C 01/20/2015 01/27/2015
C 03/15/2015 03/18/2015
C 04/01/2015 04/04/2015
I am not sure how to do this, I have tried selecting the max and min but that only gives something like, which is not what I want:
ID date_time1 date_time2
A 01/09/2015 02/19/2015
B 03/03/2015 03/06/2015
C 01/20/2015 04/04/2015
Any ideas/suggestions for how to do this would be greatly appreciated! Thank you!