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

Leslie Perez
Leslie Perez
943 Points

I keep getting an error with this query

I don't understand what I am doing wrong

Leslie Perez
Leslie Perez
943 Points

SELECT title, LENGTH(title) AS longest_length FROM books ORDER by longest_length LIMIT 1;

4 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 46,164 Points

If you order by longest_length the longest will be at the bottom of the list. If on the other hand you select the books by length in descending order you'll retrieve the correct book.

SELECT title, LENGTH(title) AS longest_length FROM books ORDER by longest_length DESC LIMIT 1;
Leslie Perez
Leslie Perez
943 Points

Thank you!! Can you tell me what I'm doing wrong on this one? SELECT first_name || " " || last_name || " " || <email> AS to_field FROM patrons;

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 46,164 Points

The angle brackets are not part of the field name for email. They should be concatenated as text.

SELECT first_name || " " || last_name || " <" || email || ">" AS to_field FROM patrons
Leslie Perez
Leslie Perez
943 Points

Awesome! Thank you!!

Halley Caldwell
Halley Caldwell
2,681 Points

Just a quick follow up on this. I also used this :

SELECT title LENGTH(title) AS longest_length FROM books ORDER by longest_length DESC LIMIT 1;

As my answer. However, I did not have the "," after SELECT title and it was counted as wrong. Is there a reason for this?