In principle I have 2 tables T1 and T2, each containing a date-field, lets call it date:
T1: date | somekey | data ...
T2: date | somekey | data ...
I want to (left)join T1 and T2, such that the result has all rows from T1.
Now for each row from T1 I need the values from the (exactly one) row of T2 joined where ABS(DATEDIFF(T1.date,T2.date)) is minimal and T1.somekey=T2.somekey (or null in case there is no such row in T2)
Don’t do it in the
JOINclause, just put it in theWHEREclause.EDIT:
I think I get what you want to do, but subqueries are the way to go here: