MySQL Forums
Forum List  »  Newbie

How do you get both the value from the CURRENT row and the value from an ADJACENT row?
Posted by: Montana Burr
Date: December 30, 2021 02:28PM

I have a table that looks like this:

ID eventID eventDate
0 1 2021-11-01
0 2 2021-11-15
1 1 2021-11-12
1 2 2021-11-14

I want to SELECT somehow and return this result:

ID currentEventID currentEventDate NextEventDate
0 1 2021-11-01 2021-11-15

etc.

Typing this out gives me an idea:

SELECT t1.ID, t1.eventID, t1.eventDate, t2.eventDate
FROM table t1
JOIN table t2
ON t2.eventID = t1.eventID + 1

Options: ReplyQuote


Subject
Written By
Posted
How do you get both the value from the CURRENT row and the value from an ADJACENT row?
December 30, 2021 02:28PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.