Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Lesedi Kwatsherema
8,390 PointsGet the 101st to 200th actor from the actors table. Be sure to return every column. Also, there's no need to use any ord
How do you solve this using limit and offset?
I have tried this SELECT * FROM actors LIMIT 10 OFFSET 200; OR SELECT * FROM actors LIMIT 101 OFFSET 200; OR SELECT * FROM actors LIMIT 200, 10; OR SELECT * FROM actors LIMIT 200, 101;
None of the above is not working. I am not sure if this "101st" is the 10 first or not. Please assist
2 Answers
Vedran Brnjetić
6,004 PointsI don't see the rest of the question, so I don't know what do you need 10 for. Based on the part of question I can see, I conclude the following:
You need to return actors from 101 - 200.
So, you need to return exactly 100 actors.
Also you need to skip the first 100 actors.
first number in LIMIT clause defines the limit to the number of results the second number defines the number of results to skip
SELECT * from actors LIMIT 100, 100
Nolan Lapham
5,645 PointsHi Daniel,
I think to make this clearer, you should subtract 100 from both 101, and 200. Then we have the number range from 1-100, which is 100 numbers. Although you are correct, 200-101=99 (or 100-1=99 in my example), in the SELECT statement we are counting the value of (10)1, not subtracting it.
I hope this helps. Nolan
Lesedi Kwatsherema
8,390 PointsLesedi Kwatsherema
8,390 PointsThanks. Vedran. It worked perfectly
Daniel Alexander Lowes
6,049 PointsDaniel Alexander Lowes
6,049 PointsI don't understand it but Doesn't 't 200-101=99 ? Can you further explain the math?
Thank You
Daniel