Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Carter Stahl
Carter Stahl
3,767 Points

Ordering the Result Set Challenge

What am I doing wrong?! Get the 11th to 30th movie from the movies table. (Again no need to order the results).

'''SELECT * FROM movies LIMIT 10 OFFSET 1;'''

2 Answers

Peter Ramsing
Peter Ramsing
16,814 Points

Try this:

SELECT * FROM movies LIMIT 20 OFFSET 10;

By setting your OFFSET to 10, that means it will start the count at 11 and then you are counting 20 units, thus this will display the movies between 11 and 30.

Robert Bojor
PLUS
Robert Bojor
Courses Plus Student 29,439 Points
SELECT * FROM movies LIMIT 10, 20

should do the trick... since the limit is just like an array, 0 indexed, by specifying 10 as the first parameter you start from the 11th entry and the second parameter is the slice size, in this case 20, to get to the 30th entry and include it as well in the result.

its working thanks

I'm a bit confused. This works, but I'm still struggling with the concept.

Since it's zero-indexed, one would think that setting it to 10 would have it go up to 9. How does setting it to 10 make it select the first eleven?

If I start typing numbers:

0123456789 (that is 10 numbers, starting at zero).

If someone could explain or offer some insight, I would greatly appreciate :)

Thanks!