Page 1 of 1
how do i find the next and last id number
Posted: Wed Jan 08, 2003 10:59 am
by runelore
if i have id number 13 from database and i want to find the id number of the item in teh database before this id (they are not all incremented) how do i do it... also how do i find the id number of the next item on the database.? thanks for any help..
Posted: Wed Jan 08, 2003 11:06 am
by DaiWelsh
SELECT id FROM tablename WHERE id < {13 or your id variable} ORDER BY id DESC LIMIT 0,1
for last id
SELECT id FROM tablename WHERE id > {13 or your id variable} ORDER BY id ASC LIMIT 0,1
for next id.
HTH,
Dai
Posted: Wed Jan 08, 2003 11:07 am
by runelore
thank you very much.... that works a treat....