This could be a very basic problem, but I sort of don't know SQL at all.
To simplify the problem, let there be a table with only one column, so I can write down the rows horizontally:
1 3 11 39 41 45 52 63 66 70 72 80 81 90 92 97
As you can see, they are sorted. Now, I know there is the row with "70", and I want to query five rows before it in ascending order. That is, I want
41 45 52 63 66
How should I do the query?
I can query the five rows in descending order and reverse the result set afterwards, but I think there should be a better way.
Below is the query that I was able to come up with, but I am not sure whether this is what you require and moreover the result is in descending order.
I created a table, SAMPLE, with index1 as its only column:
SELECT * FROM SAMPLE WHERE index1 < 70 ORDER BY index1 DESC LIMIT 0,5;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With