After you have selected my self join, I think you will have to generate row_numbers for each sub_query:
select @rn1 := @rn1+1 as ra, t1.id, t1.eventDate
from events t1
join (select @rn1 := 0) r;
and then attach this to
select @rn2 := @rn2+1 as rb, t2.id, t2.eventDate
from events t2
join (SELECT @rn2 := 0) r;
so the final answer is:
select ta.id, ta.eventDate from
(
select @rn1 := @rn1+1 as ra, t1.id, t1.eventDate
from events t1
join (select @rn1 := 0) r
) as ta
join
(
select @rn2 := @rn2+1 as rb, t2.id, t2.eventDate
from events t2
join (SELECT @rn2 := 0) r
) as tb
on rb = ra+1 and ta.id = tb.id and ta.eventDate = tb.eventDate
Results:
February 1, 27 2014 23: 21: 41 + 0000
February 2, 27 2014 23: 25: 08 + 0000
February 3, 28 2014 15: 36: 55 + 0000
February 4, 28 2014 19: 33: 31 + 0000
source
share