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 trialDavid Corrales
4,698 PointsSome small minor error perhaps reporting with SQL, can someone help?
Challenge Task 1 of 1 In the library database there's a books table with the columns id, title, author, genre and first_published.
Find the book with the longest title. Show the title and then the length. Alias the result of the length calculation to be longest_length. Only retrieve the longest book.
Type in your command below, then press Ctrl-Enter.
Bummer: Your query didn't retrieve the longest book title with it's length.
SELECT title, LENGTH(title) AS longest_length FROM books LIMIT 1;
3 Answers
Steven Parker
231,248 PointsYou're close, and the "LIMIT" does the job of returning just the first result; but it's not necessarily the longest one.
Hint: You might also want to use "ORDER BY".
David Corrales
4,698 PointsOh my gosh you're the best! I did it! yayy! Thanks to your help!
Shantanu Trivedi
1,337 PointsIn this same problem: In the library database there's a books table with the columns id, title, author, genre and first_published.
Find the book with the longest title. Show the title and then the length. Alias the result of the length calculation to be longest_length. Only retrieve the longest book.
I have written this piece of code: SELECT title, LENGTH(title) AS "longest_length" FROM books ORDER BY DESC LIMIT 1; But it shows the error: Bummer: There's something wrong with your SQL statement. Please review your code and try again. I am not sure, what I am doing wrong?
Steven Parker
231,248 PointsAsking a question as an "answer" to another question!
Starting a fresh question will give you the best chance of a prompt answer.