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

Why am I being told there is a problem with the syntax in my query?

On one of the Reporting with SQL challenge tasks I am told to create a query to obtain the first 5 books from the "Fantasy" genre organized the release, with the oldest listed first. I can't figure out what the problem is.

Umesh Ravji
Umesh Ravji
42,386 Points

Show us what you have written :)

4 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Brian, I'm going to simplify the structure of a query a little, but it should be plenty to point out how it should go. You have all the right stuff in your query, it's just not in the right place.

SELECT [columns] FROM [table] WHERE [conditions] ORDER BY [columns] LIMIT x

Umesh,

Thank you for the clarification :)

Hi James,

Here is the query I tried submitting

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

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

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

the order by goes later in the code, right before limit i think. also if it asks for certain columns, like title, using the universal selector (*) will probably cause an error. so if they just wanted the titles, i think it would be something like:

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

James,

Thank you so much for your help!