Answer the question
In order to leave comments, you need to log in
How to get next and previous value?
Greetings,
Let's imagine that there is a primitive table with one column that stores arbitrary numerical values. Is there some way built into mysql to get N next M previous values given a certain value?
For example, the table stores the values - 2, 6, 10, 15, 1, 14
We have the value 10. How to get the previous (6) and next (15) values?
There are no other fields on the basis of which it would be possible to implement logic in the table (there is no autoincrement). The numbers are arbitrary and it is impossible to calculate "neighbors" using any formula. The option to get all records, for example, into an array will not work.
Answer the question
In order to leave comments, you need to log in
You need to store the offset in a separate column. Knowing the offset of the current line, then jump using LIMIT and OFFSET .
There are also cursors , but there you can only move in one direction.
Most likely, relational databases are not suitable for your task.
There are no other fields on the basis of which it would be possible to implement logic in the table (there is no autoincrement)
SELECT value FROM table WHERE value > 10 ORDER BY VALUE LIMIT 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question