I've got a table with the following data. "record_id" is the autoincremented primary key, "name" is indexed.
record_id name payload
1 a x
2 b y
3 c y
4 b z
5 a z
6 a w
7 b y
8 c x
How can I get pairs of consecutive rows for each "name"? I understand that I must join table to itself, but can't figure out how to join only the first of the rows with record_id greater than the one being processed. NULL-filled part after the last row for any "name" is important as well. Again, I understand that I probably must use LEFT JOIN for that.
1 a x 5 a z
5 a z 6 a w
6 a w NULL NULL NULL
2 b y 4 b z
4 b z 7 b y
7 b y NULL NULL NULL
3 c y 8 c x
8 c x NULL NULL NULL
I'm using MySQL pre-8.0, so I can't use window functions if that matters.
Thanks a lot.