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 trialPatrick Alcorta
4,056 Pointslimit result challenge
Maybe I am not reading the question properly but they are asking to limit the rows by five, order it by year that the book was published right? So I put int my code:
select * from books order by first_published asc limit 5;
and it gives me the error " You are missing a WHERE "
Is there something I am doing wrong? Please advise D:
Vittorio Somaschini
33,371 PointsHello Patrick,
I have edited your code formatting for readability, please have a quick look here: https://teamtreehouse.com/forum/posting-code-to-the-forum
Thanks
Vitto
2 Answers
Andrew Winkler
37,739 PointsOk, so they are asking to limit the rows by five - well that means you should write LIMIT 5
at the end of the statement.
Then, order it by year that the book was published - that means you should write ORDER BY first_published ASC
the 2nd to last statement position (preceding right before the limit statement mentioned earilier).
So that would provide you with:
SELECT * FROM books ORDER BY first_published ASC LIMIT 5;
Which is what you have so props - but I looked back though and you're missing part of the question:
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.
Therefore, you are missing a WHERE
clause and the proper code would be:
SELECT * FROM books WHERE genre = "Fantasy" ORDER BY first_published ASC LIMIT 5;
P.S. next time please remember to quote the question.
Patrick Alcorta
4,056 PointsThank you very much for the quick reply :), going forward I will also post the question xD.
Kevin Faust
15,353 PointsKevin Faust
15,353 Pointscan you provide a link to the challenge?