'How to get next highest number from mysql rows, given one row id
How to get next highest number from mysql rows, given one row id.
Eg.
Categories | sort_order
Animal | 400
Cars | 500
>
Vans | 550
Now I want to add a category under Cars, over Vans which I have to check what is next highest number after 500.
So when I add 400 should return 500, when 500 should retrun 550.
Solution 1:[1]
Should be as simple as the following:
SELECT MIN(sort_order) FROM mytable
WHERE sort_order > 500;
Solution 2:[2]
select min(sort_order) + 1 from tablename where sort_order >= 500
Untested, but should work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Faber |
| Solution 2 | jarlh |
