This is a SQL join with between
, not a join condition.
select t1.col_1, t1.col_2, t1.my_date, t2.the_value from table_one t1 join table_two t2 on t1.my_date between t2.date_1 and t2.date_2;
Note that between
includes borders, so it also returns strings where my_date
is 2010
. If you do not want you to use the join condition with >
and <
:
select t1.col_1, t1.col_2, t1.my_date, t2.the_value from table_one t1 join table_two t2 on t1.my_date > t2.date_1 and t1.my_date < t2.date_2;
It also requires your date ranges to be non-overlapping, otherwise you would get some weird results.
source share