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.

Databases

i would like some help topic database paging through results!!!!!!!!!!!!!!!!

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. Please retrieve all columns of information.

topic : paging through result, challenge one!

Select*From order by limit 10 offset 10<skipped rows>;

2 Answers

thanks!!

Hi,Steven ! I would like to ask you how do you post code colourful, with red, green,blue ??????????????

Steven Parker
Steven Parker
216,108 Points

When you format your code using the instructions in the Markdown Cheatsheet (you'll find it below the text entry area :arrow_heading_down:) and you include your language in the opening quote line, the system applies syntax highlighting for you.

Also, when you select a "Best Answer" to a question, it should be the answer that most directly addresses the question you asked and/or the one that helped you the most. Other readers my rely on your choice to help determine a good reply from a bad one.

Steven Parker
Steven Parker
216,108 Points

Is your issue just the paging?

I'm going to assume you're comfortable with the rest of the query instructions. So if you are displaying 10 entries at a time, then your LIMIT is 10. And if you want to see the second page, that would mean you want to skip the first page of 10, so your OFFSET would also be 10.

Does that answer your question?

In future, to enable the most complete and accurate analysis, always post your code along with a link to the course page.

hello Steven! Can you check my code because is not working! thanks.

Steven Parker
Steven Parker
216,108 Points

Examining this code:

Select*From order by limit 10 offset 10<skipped rows>;
  • you forgot to put the table name after FROM
  • you forgot the sort criteria after ORDER BY
  • you wrote "<skipped rows>" which is not a valid comment (as a comment it would be "/*skipped rows*/")
  • it would be good practice to have a space on either side of the asterisk
SELECT * FROM books ORDER BY title LIMIT 10 OFFSET 10/*skipped rows*/;