I have two tables with dates. Between (!) every two following dates in table1, I want to know the number of dates in table2. How do I write an SQL query for this? The tables I have are up to a few hundred records in table 1 and a few thousand records in table2. So to prevent that this takes hours I need a fast query.
To explain the query I need, for example:
table1
01/01/2014
15/01/2014
17/01/2014
30/01/2014
table2
01/01/2014
02/01/2014
05/01/2014
17/01/2014
18/01/2014
20/01/2014
21/01/2014
25/01/2014
So the answer of the query would be 2,0,4.
Explanation:
Between 01/01/2014 and 15/01/2014 in tbale 1 there are 2 dates in table2 (01/01/2014 is not included between the dates)
Between 15/01/2014 17/01/2014 in tbale 1 there are 0 dates in table 2
Between 17/01/2014 30/01/2014 in table 1 there are 4 dates in table 2
Can anyone help?