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 Reporting with SQL Working with Text Getting the Length of a String

longest length

I'm asked to return the title, and length as an alias with the highest one being returned.

I'm not seeing what the issue is?

2 Answers

Steven Parker
Steven Parker
231,184 Points

Do you mean you don't understand the instructions? Let's break them down:

"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."

So you'll need to:

  • select the title, and the length of the title
  • give the length an alias as the name
  • order by the length of the title
  • order with descending values (longest titles first)
  • limit the results to just the first one

I'll bet you can get it now — give it a try.

Steven,

Yes I see what I did...

select title, LENGTH(title) as longest_length FROM books ORDER BY length desc limit 1; --This failed

select title, LENGTH(title) as longest_length FROM books ORDER BY longest_length desc limit 1; --This PASSED

I didn't order by by Alias longest_length appropriately.

Thanks!

Steven Parker
Steven Parker
231,184 Points

Glad to help. In future questions, be sure to include your query code with the question.