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 trialYounes Zoughbi
6,233 PointsFind the actor with the longest name.
Using the SQL Playground Stage 2 Practice Question 1.
My code:
SELECT name AS longest_length FROM actors ORDER BY longest_length DESC LIMIT 1;
I am aware that I am missing something, and it is not correctly displaying the right result.
If I'm not mistaken, I am currently just renaming the name AS longest_length.
Any advice is appreciated.
3 Answers
Steven Parker
231,236 PointsIf you order by the name itself (desc), you'll just get the name that comes last alphabetically. You could order by the LENGTH
of the name instead.
Charlie Harcourt
8,046 PointsSELECT name,LENGTH(name) AS longest_length FROM actors ORDER BY longest_length DESC LIMIT 1;
:)
Younes Zoughbi
6,233 PointsMuch clearer, thank you for the explanation.