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 trialSobin Sebastian
5,348 PointsWe're using library database again. There's a books table. There's a title, author, genre and first_published column.
We're using library database again. There's a books table. There's a title, author, genre and first_published column. Write a query to obtain the first 5 books in the Fantasy genre ordered by the year released. Oldest first. Select all rows.
5 Answers
Tobias Helmrich
31,603 PointsHey there,
first you have to get all the books with the genre of "Fantasy" using a WHERE
clause. After that you have to order them using the ORDER BY
keywords by the year they were published, beginning with the oldest ones, which means that you have to use the ASC
keyword in the end. In the end you should specify that you only want to have the first 5 books of the results which you can achieve by using the LIMIT
keyword with the value 5.
SELECT * FROM books WHERE genre = "Fantasy" ORDER BY first_published ASC LIMIT 5;
I hope that helps! :)
morris masila
782 PointsSELECT * FROM books WHERE genre = "Fantasy" ORDER BY first_published LIMIT 5; You need to get rid of the ASC keyword. you can try this.I think its the right one.
SOUL DIGITAL
Courses Plus Student 18,704 PointsTry:
SELECT * FROM books WHERE genre = "Fantasy" ORDER BY first_published ASC LIMIT 5;
Jordan Olson
6,155 PointsWhy is this quiz asking us to answer things not covered? When was it that we were told we can specify a string for the genre or the 'column'?
Chipo Makawa
5,919 PointsSELECT * FROM books WHERE genre = "Fantasy" ORDER BY genre asc, title asc LIMIT 5;
Sobin Sebastian
5,348 PointsSobin Sebastian
5,348 Pointsthnx got it :)
A X
12,842 PointsA X
12,842 PointsHi Tobias (or another person), Why is this version of the query incorrect? In other words, why must LIMIT 5 go at the end? I'm telling the query the exact same information, just in a different order.
SELECT * FROM books WHERE genre = "Fantasy" LIMIT 5 ORDER BY first_published ASC;
Daniel H. Kim
5,333 PointsDaniel H. Kim
5,333 PointsThank you. This was helpful since it helps to understand the step by step logical process thought.
Emily Ley
2,561 PointsEmily Ley
2,561 PointsI put AND between all the conditions. Why did that not work?