In the below i have a table1,table2 ,i am stuck with a query.I want find the timestamps in table2 which are in between two consecutive timestamps of table1 .How to form this query.
table1:
id timestamp
1 2012-08-15 01:11:11
1 2012-08-15 01:11:14
1 2012-08-15 01:11:16
2 2012-08-15 01:22:11
2 2012-08-15 01:32:11
2 2012-08-15 01:33:11
2 2012-08-15 01:36:11
table 2:
id timestamp
1 2012-08-15 01:11:12
1 2012-08-15 01:11:15
1 2012-08-15 01:11:16
2 2012-08-15 01:23:55
2 2012-08-15 01:26:11
2 2012-08-15 01:34:11
2 2012-08-15 01:36:01
Desired output:Get all rows of table2 which are in between the timestamps of table1 and if possible output timestamp of table1 also
Join
table1to itself and then group to find consecutive timestamps, then join the result totable2as desired:See it on sqlfiddle.