Jump to content

Mysql - Query to get next & previous ID


thestars

Recommended Posts

How can I get the very next Primarykey and just previous Primarykey of a given row using mysql query?

 

OK if you want the next and prev record from a given row just us > < opeartors

 

// next row

SELECT id FROM table WHERE id > 123 ORDER BY id ASC LIMIT 1

// prev row

SELECT id FROM table WHERE id < 123 ORDER BY id DESC LIMIT 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.