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

2
  • 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? Commented Jan 5, 2017 at 15:31
  • Take a look at stackoverflow.com/questions/1446821/… , it might be helpful. Commented Jan 5, 2017 at 15:32

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

3 Comments

In the absence of an ORDER BY clause, LIMIT is fairly meaningless.
@Strawberry - you are right - i will add it in my answer (sorry)
There's still a LIMIT there without an ORDER BY !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.