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

Carol Garcia
Carol Garcia
1,875 Points

What am I doing wrong in this query?

Below is my code:

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi, Carol Garcia ! It looks like you're doing terrific thus far! The problem is in your ORDER BY. You just made an alias for the length of the title together with the title and named it longest_length. This is what you should be ordering by :smiley:

Try changing this part:

ORDER BY title, length

To this:

ORDER BY longest_length

Hope this helps! :sparkles:

Carol Garcia
Carol Garcia
1,875 Points

Wow thank you, Jennifer, that worked! I'm still not sure how though so allow me to work it out if you'll confirm. Below was the original example given in the video which I tried to follow but it did not work. SELECT username, LENGTH(username) AS length FROM customers ORDER BY length DESC LIMIT 1; "length" is the alias for username and length of username right?

In my answer "longest_length" is the alias for title and LENGTH(title), right (below in corrected format)? SELECT title, LENGTH(title) AS longest_length FROM books ORDER BY title, length DESC LIMIT 1;

Tommy Gebru
Tommy Gebru
30,164 Points

I believe "longest_length" is only an alias for one parameter, consider also that your alias will replace the column description, so you can count out how many columns are displayed as well :thumbsup: