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

I keep getting an error with this query

I don't understand what I am doing wrong

Can you post your SQL?

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

4 Answers

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;

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;

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

Awesome! Thank you!!

Kris C
Kris C
3,442 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?