Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases SQL Basics Finding the Data You Want Review & Practice with SQL Playgrounds

Last Name Cruise

Find all the actors with the last name of Cruise.

I see two columns in table actors. One column is id and the other is name. I am not sure how to write a SQL statement that pulls the last name out of the names column only when the column contains data with first, middle and last names all together.

Any help would be welcome.

I see an a post with all the answers but I would also appreciate an explanation of the solution, which appears to be

SELECT * FROM actors WHERE name LIKE ("%Cruise%");

How does placing the wildcard % before and after the name Cruise signify that it's the last name rather than the middle and the first? Is that just the convention for using the % wildcard in SQL?

1 Answer

SELECT * FROM actors WHERE name LIKE "%Cruise"; You are using the wildcard before so that it doesn't matter what the first name is. No wildcard after because you are just looking for Cruise. If there had been a name such as Cruiseland is would return that had you included the wildcard after cruise also. Hope this helps

JASON LEE
JASON LEE
13,655 Points

Does it matter whether it is "%Cruise" or "% Cruise"? What happens if the name was "Bob McCruise" ? The query would still pull that result, but Bob's last name is McCruise, and not Cruise.