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

PHP

LIMIT and OFFSET - 2 objectives: Challenge Task 1 of 2: Not understanding the question (I guess!)

The task is as follows: Note: We will be writing ONLY the SQL query for this challenge. In a library database there's a books table. There's a title,author, genre and first_published column. The library database is connected to a website displaying 10 books at a time, sorted by the title alphabetically. Write a query to bring back the second page of results.

I submit: select title from books order by title LIMIT 10 OFFSET 10; Response back: Your query needs to retrieve the earlier 'Science Fiction' book from the books table.

What? The task never mentioned science fiction books only.

So I change my query and submit: select title from books where genre = 'Science Fiction' order by title LIMIT 10 OFFSET 10; Response back: Ten books were expected. 0 were returned in the results.

For grins, I submit: select title from books order by title LIMIT 10 OFFSET 11; Response back: Ten books were expected. 9 were returned in the results.

What? Now, I don't need the 'Science Fiction' book only check?

What am I missing!!! ?????

Thanks, Karen

2 Answers

pooja tandan
pooja tandan
5,225 Points

SELECT * FROM books ORDER BY title LIMIT 10 OFFSET 10;

Thanks!

Joel Bardsley
Joel Bardsley
31,249 Points

A curious response message indeed! I've just gone through the task and the only thing I noticed that was wrong with this query:

select title from books order by title LIMIT 10 OFFSET 10

...was that you were only selecting the 'title' column, whereas the question didn't specify any particular columns. Everything else looked good, just assume to select everything unless told otherwise.

Thanks.