Skip to content
Advertisement

Return all records that has particular record following next to it

I have few records sorted by Serial Number and I need all records such that a record followed by another record satisfying given condition.

Table student -> CREATE TABLE student (sno int, id int, firstname varchar(255));

Condition: Record should have firstname = “alex” and must be followed by record with firstname = “justin”

Advertisement

Answer

You can use lead()/lag():

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement