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

Development Tools Database Foundations Reading Data from Databases with SQL Limiting the Result Set

Martin Bornman
PLUS
Martin Bornman
Courses Plus Student 12,662 Points

In the code challenge first Question . My Answer Is: SELECT * FROM actors LIMIT 99,100; Help please

LIMIT

4 Answers

Alex Heil
Alex Heil
53,547 Points

hey Martin Bornman , I guess you're reffering to this code challenge question: Get the 101st to 200th actor from the actors table. (No need to use any ordering).

if so, you're actually really close ;) only problem, might be because of the nature of the question, is that you're quering 99 results. however even if the difference from 101 to 200 would be 99 when we include the 101st answer then you actually want to get 100 answers back - I guess you already see the prob, right?

so if we want to get all 100 results form 101 to 200 our statement would look like this:

select * from actors limit 100 offset 100;

hope that helps and have a nice day ;)

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Alex. So LIMIT 100 means we skip 100 rows to row 101, and to query every row from there to the 200th we type OFFSET 100; ?

OFFSET refers to row, and since mySQL numbers rows beginning with "0" (i.e. zero is the first row of any table), then row 101 has be referenced as row #100. So: "OFFSET 100"

The correct answer can have two forms:

SELECT * FROM actors LIMIT 100 OFFSET 100;

Or, in the "shorthand" explained in the video:

SELECT * FROM actors LIMIT 100, 100;
Sarah A. Morrigan
Sarah A. Morrigan
14,329 Points

Yeah... I misunderstood the thing.

So LIMIT 100 OFFSET 100 could better be said as "display 100 entries, after entry number 100."

Sarah A. Morrigan
Sarah A. Morrigan
14,329 Points

Hi, I am VERY bothered by the totally incomprehensible code challenges in this section as well.

"Get the 101st to 200th actor from the actors table. (No need to use any ordering)."

if I take the idea from the video, it should look like

SELECT * FROM actors LIMIT 100 OFFSET 1; by limiting display to 100 actors (100st to 200th is 100 actors, not 99) with offset for data range 101-200 being the "second page" of the display whereas actors 1 through 100 being "first page" or OFFSET 0.

So I see no reason why it should be LIMIT 100 OFFSET 100. :(

You have the first part of the query right, "SELECT * FROM actors LIMIT 100" which will get you 100 actors. The OFFSET part refers to which row you would start to count the 100 actors. As you want to start with the 101st actor, since the row count starts at 0 use OFFSET 100. I don't think we have learned any way to make a query return the data arranged in multiple pages yet, just how to select a single subset of the data.