mysql - If I specify any value for an auto-increment field, how can I get the next or previous value? -


i have mysql table auto-increment field , trying figure out how next or previous value along rest of row using purely mysql. field ai numbers aren't consecutive rows deleted time.

field_id 8, 15, 17

this started with:

//to next value in table: select min(member_id) val members member_id > 15 limit 1  //to previous value in table: select max(member_id) val members member_id < 15 limit 1 

but returning member_id value. works next value (but doesn't make difference if use desc or asc (wtf):

select min(member_id),members.*  val members  member_id > 15  order member_id desc  limit 1 

that query reversed (to the previous value) returns lowest value in table (1):

select max(member_id),members.*  members  member_id < 15  order member_id asc  limit 1 

these 2 queries, however, shows want not entirely sure why:

//get next lowest row select max(member_id),members.*  members  member_id < 15  group member_id     order member_id desc  limit 1  //get next highest row: select min(member_id),members.*  members  member_id > 15  group member_id     order member_id asc  limit 1 

i'm assuming group allows me pull more 1 row query? there better way this?

//to next value in table: select * members member_id > 15 order member_id limit 1  //to previous value in table: select * members member_id < 15 order member_id desc limit 1 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -