0

I have one row that i can SELECT with the following command:

SELECT * FROM uploads WHERE upload_id = $upload_id

But I also want to get the 5 next rows. Using PHP, how can i do that? Order doesn't matter.

4
  • SELECT * FROM upload WHERE upload_id >= $upload_ID LIMIT 6, assuming things are sorted naturally by that upload_id Commented Nov 21, 2013 at 21:53
  • 1
    which 5 rows? 5 random rows, or 5 rows with the next upload ids? Commented Nov 21, 2013 at 21:53
  • 3
    How can you on one hand say you want the "NEXT" five rows and then also say "Order doesn't matter". These statements don't jive. What do you actually want? Is there an autoincrementing id here for upload_id? Commented Nov 21, 2013 at 21:54
  • Ha I didn't read the "order doesn't matter" bit Commented Nov 21, 2013 at 21:55

2 Answers 2

1

To get that record and the next 5 ascending upload_ids:

SELECT * 
FROM uploads 
WHERE upload_id >= $upload_id
ORDER BY upload_id ASC
LIMIT 6
Sign up to request clarification or add additional context in comments.

Comments

0

You can try:

select * from uploads where upload_id >= $upload_id order by upload_id asc limit 6;

You should also really avoid using select * and instead specify only the fields you need, even if that is all of the fields. That way if the schema changes in the future you aren't returning redundant data.

Comments

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.