[SOLVED] How to get next highest number from mysql rows, given one row id

Issue

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

Should be as simple as the following:

SELECT MIN(sort_order) FROM mytable
 WHERE sort_order > 500;

Answered By – David Faber

Answer Checked By – Senaida (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.