This is not the answer to your real question.
Instead, I feel that you are approaching the problem from the wrong direction: In properly normalized relational databases, the tuples ("rows") of each table should contain references to other db elements instead of the actual values. Maintaining this relationship between tuples refers to the part of entering code base data. That is, if you contain the value of the tuple with the closest, the smaller identifier number really belongs to your data model.
If the requirement to find out the previous value comes from a part of the applicationโs view - that is, one view into the data that needs to be formatted in a certain order - you have to pull out the contents, sort by id and process the request in view of the specific code.
In your case, I would suggest that knowing the meaning of previous tuples would really belong to the view code instead of the database.
EDIT: You mentioned that you store them separately and just want to make a request for it. Even so, the application code is likely to be a more logical place for this association.
source share