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 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

emmagx
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
emmagx
PHP Development Techdegree Graduate 18,239 Points

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

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.