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

Using wildcards: putting it at the end vs enclosing the phrase with wildcards

-- Find all Playstation 4 products. Try and do this with 3 different queries.

I used the query below. The presenter puts the wildcard only at the end. Is there a particular reason why he would put it at the end like "Playstation 4%" rather than at each of the two sides to find all Playstation 4 products?

SELECT * FROM products WHERE name LIKE "%Playstation 4%";

1 Answer

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

Hi there, Ra Bha! It's probably because adding the wildcard to both sides might get you more results than you're counting on. For instance, if there were a product named "Happy Toddler Playdough Playstation 40", that would also match. Having the wildcard on either side says "if this is found anywhere in that string, include it in the results". So the above would also match, even though it's clearly not the gaming console we had in mind :smiley:

Hope this helps! :sparkles: