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

Robbie Thomas
Robbie Thomas
31,091 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
Treehouse Moderator 10,987 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;