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

Shreemangal Sethi
Shreemangal Sethi
8,386 Points

Could someone pls tell me whats wrong with this statement.

Please tell me whats wrong with this SQL statement.

4 Answers

Shreemangal Sethi
Shreemangal Sethi
8,386 Points

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

KRIS NIKOLAISEN
KRIS NIKOLAISEN
53,693 Points

You will want to order by longest_length instead of the length function

Kiran Kumar
Kiran Kumar
5,039 Points

There's no column called length in the table, books; Like Kris explained above use the alias, longest_length which contains length of title.