Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases Reporting with SQL Working with Text Getting the Length of a String

Robbie Thomas
Robbie Thomas
31,093 Points

Getting the length of a string

Not exactly sure what they want here. This is my answer:

SELECT books, LENGTH(title) AS "longest_length" FROM title ORDER BY length DESC LIMIT 1;

1 Answer

Gabriel Pierce-Lackey
Gabriel Pierce-Lackey
11,014 Points

Okay, a few things. first, you don't need the quotes around longest_length or around any alias. its just name AS nm. Ya know. Secondly were taking the title from the table books, not the column books from the table title. And sine we want the length of the title as well. Were selecting title twice, one is going to the length.

SELECT title, length(title) as longest_length FROM books order by longest_length desc limit 1;