Reputation: 147
I want to achieve something very similar to this but using MySQL:
Group rows if certain column value directly after another in SQL
However, in my case the id is not incremented by 1 but there is a random gap so for instance:
0 -- bob -- note -- 14:00
3 -- bob -- note -- 15:00
9 -- bob -- time -- 15:00
20 - bob -- note -- 15:00
I need to display:
0 -- bob -- note -- 14:00
9 -- bob -- time -- 15:00
20 - bob -- note -- 15:00
Any help would be greatly appreciated :)
Upvotes: 1
Views: 344
Reputation: 26143
select id, Name, Event, Time
from (select *, @e prev, @e:=Event
from table, (select @e:='') e) t
where prev<>Event
Upvotes: 2