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

Databases

ISSUE USE ORDER BY AND LIMIT IN SQL

I dont know why it Bummer!.Please help me

[CHALLANGE] 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.\n

[BUMMER] Bummer! Your query needs to retrive the earliest 'Science Fiction' book from the books table.

[CODE]

 SELECT*FROM books ORDER BY title LIMIT 10 OFFSET 3

Thanks

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi there.

Try adding a keyword to explicity set the default order.

 SELECT*FROM books ORDER BY first_published ASC LIMIT 10 OFFSET 20

If ASC doesn't work try DESC as keyword after the first published colum.

Also you want to target the second page of 10 results. So try offsetting by 20.

I dont know why you use first_published when this challenge say sorted by the title alphabetically. Thanks

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

My understanding from the bummer message is that you want to retrieve the earliest published books first so this will need a certain sorting somehow.

I suggest trying this query although I'm not sure why it doesn't pass. It orders the title field alphabetically and ensures the earliest published books come first.

SELECT * FROM books ORDER BY title ASC, first_published DESC LIMIT 10 offset 10
Yash Kesarwani
Yash Kesarwani
3,431 Points

SELECT * FROM books ORDER BY title ASC LIMIT 10 offset 10;

Thanks it only wrong in offset 10