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

Zachary Wheeler
Zachary Wheeler
1,157 Points

Very First Reporting SQL Challenge Question

SELECT * FROM books ORDER BY first_published LIMIT ASC 5;

It asks us to input a code querying the first 5 in ascending order, but it says i'm missing WHERE. I don't know where to put the WHERE. Can you help me?

first, there is a mistake in your code, no biggie but:

SELECT * FROM books ORDER BY first_published ASC LIMIT 5;

second, the question is asking for fantasy books.

Sql queries are generally in this format (I find it easier to write my queries in this layout):

select
from
where
[other]
[limit]

So the answer would be something like:

SELECT * 
FROM books 
WHERE ...
ORDER BY first_published ASC 
LIMIT 5;

I will leave the rest for you to fill in ;)

Zachary Wheeler
Zachary Wheeler
1,157 Points

Thanks, I entered in the info and now it is saying that I didn't request 5? Here is what I have:

SELECT * FROM books WHERE genre ORDER BY first_published ASC LIMIT 5;

Let me know what I can fix. Thanks

3 Answers

Steven Parker
Steven Parker
231,271 Points

You didn't finish your WHERE clause.

I see that you started to write it, but you didn't finish testing for the Fantasy genre.

SELECT * FROM books WHERE genre = "Fantasy" ORDER BY first_published ASC LIMIT 5;

The incomplete test was rejecting every genre, producing 0 books instead of 5.

Zachary Wheeler
Zachary Wheeler
1,157 Points

oh that makes sense now. Thanks so much!

SELECT * FROM books WHERE genre="Fantasy" ORDER BY first_published ASC LIMIT 5;

Nice answer Imad - concise. I like it.

Steven Parker
Steven Parker
231,271 Points

...and a loooong one, with a 6-month delay time. :wink: