get previous or next id in mysql using select query

by Ramya 2013-10-09 17:03:17

Get Previous, Next ID in MySQL:

Use Select Query, to get previous,next id in mysql.

Get Next auto-incremented id,

select id from tab where id > 1 ORDER BY id DESC limit 1;



Get Previous auto-incremented id,

select id from tab where id < 2 ORDER BY id DESC limit 1;


use can also use a variable instead of the given number in the code as,

select id from tab where id > $getID ORDER BY id DESC limit 1;
657
like
0
dislike
0
mail
flag

You must LOGIN to add comments