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

Having trouble with Practice Session! -- Please help.

I am wrapping up another chapter in SQL and I'm on the last assignment. If you follow this link and launch the SQL Playground, then, click the very last task, the Truncate Names task. https://teamtreehouse.com/library/reporting-with-sql/working-with-text/practice-session. I am struggling through this, and I'm almost done. I successfully was able to make it so if the name was over 10 characters, it would concact a "..." on the end of it. But, some of the names were still under 10 characters, and it still put the ellipse there. I hope I've explained this well. Thanks in advance!

~ Gabriel

2 Answers

Steven Parker
Steven Parker
231,261 Points

I think the challenge specifically asks for names over 10 characters. But if you want to include shorter names unchanged, a UNION might come in handy:

-- return ALL actors, with longer names truncated
SELECT SUBSTR(name, 1, 10) || "..." AS "New Name" FROM actors WHERE LENGTH(name) > 10
UNION
SELECT name FROM actors WHERE LENGTH(name) <= 10;

But I don't recall if UNION had been introduced at this point in the course.

No, it hasn't. But, I've gotta start learning somewhere! Thanks for your help. This was exactly what I was looking for.

Steven Parker
Steven Parker
231,261 Points

Remember to choose a "best answer" to mark the issue resolved.

Steven Parker
Steven Parker
231,261 Points

:point_right: Did you forget to include WHERE LENGTH(name) > 10 in your query?

You know, I tried so many things that I don't remember if I did. I'll go ahead and test that right now.

Well, I implemented that code and It's now only returning names above 10 characters. It leaves out the names that are below 10 characters and should not be truncated.

SELECT name, SUBSTR(name, 1, 10) || "..." AS "New Name"  FROM actors WHERE LENGTH(name) > 10;