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!
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
Takyi AkwahCourses Plus Student 1,049 Points
Help with Length function
Somebody please show me where I am going wrong.
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: There's something wrong with your SQL statement. Please review your code and try again.
SELECT title, LENGTH(title) AS longest_length FROM books ORDER BY Length DESC LIMIT 1;
Joosep Ress3,098 Points
You don't need to order by 'longest_length' just order by "Length".
SELECT title, LENGTH(title) as longest_length FROM books order by longest_length desc limit 1;
Joel Jose5,643 Points
You can avoid the order by clause and limit by just keeping it simple:
select title, max(length(title)) as longest_length from books