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

David Corrales
David Corrales
4,607 Points

Some 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;

2 Answers

Steven Parker
Steven Parker
170,459 Points

You'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
David Corrales
4,607 Points

Oh my gosh you're the best! I did it! yayy! Thanks to your help!

Steven Parker
Steven Parker
170,459 Points

David Corrales — Glad to help. You can mark a question solved by choosing a "best answer".

And happy coding!