0

My current query is

SELECT p.* FROM proxies p where p.last_used=1

here in db, according the query select id=4 but i want to select next record wheer id=5 (For details please click on image) next row from mysql using sql Query

need help

Alvaro Flaño Larrondo
  • 5,516
  • 2
  • 27
  • 46
  • 1
    "next record" is subjective, it depends on the ordering of the data. The order it appears when just browsing through phpmyadmin is not something to rely on - database engines don't store data in any particular order (or at least, that ordering is not guaranteed). What exactly is the criteria that makes id 5 the "next" row? e.g. is the formula to look at the id of the "last used" row and increment id by 1? Or just get the next highest id? Or something else? what if a row is deleted in the meantime? – ADyson Jan 05 '17 at 15:31
  • Take a look at http://stackoverflow.com/questions/1446821/how-to-get-next-previous-record-in-mysql , it might be helpful. – Alvaro Flaño Larrondo Jan 05 '17 at 15:32

1 Answers1

2

You can use a query like this:

SELECT p.id FROM proxies p where p.id >
(SELECT p.id FROM proxies p where p.last_used=1 LIMIT 1)
ORDER BY p.id 
LIMIT 1;
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39