SQL get next entry from known ID in a single query -


i wondering how data next row in sql database, assuming know id current entry , table ordered id.

normally, when ordering id, 1 think prev/next entry, need substract/add 1 variable holding id, , run select query new id, poses problem when there holes in table, id's so:

13,14,18,21...

and on.

a way looping in programming language, running query , adding 1 every time runs until finds row, potentially taxing database. there way find in single query?

i thinking being plausible problem, considering thought second. thought of sharing solution here!

what solve this, create new query new id less/greater old one, so:

select * mytable t t.id > 27 order t.id limit 1 

by doing , limiting results 1, can guarantee entry comes after 27.

this should work date orderings.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -