• Nowhere. That's my point. In some common query scenarios you just want the "next" value, wherever that is, and that's when you need to be careful not to assume there are no gaps.

    My reading of "consecutive" is stronger than that, i.e., to be consecutive the sequence must be unbroken.

    On such a reading, it would actually be a mistake to treat 1 and 3 as consecutive just because there was no 2.

    It's not that I assumed there are no gaps; it's that I read gaps as not allowing the values on either side to be "consecutive".

    It's not the case that adding the row number and using that is something that works in all cases while mine fails in the "worst case".

    They're completely different answers to different requirements. Clarifying whether the OP meant consecutive in the sense in which I took it, or just "next" as you took it is well worth it, so thanks for mentioning it 🙂

    Cheers!

    EDIT: Fixed a typo.