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 trialMiguel Nunez
3,266 PointsTwo wild cards vs One in SQL?
I'm very confuse I started doing the code challenges and I started to realize that the teacher was demonstrating the LIKE keyword with one wild card and later in that video he started to use two wild cards with the LIKE operator which I said to my self it doesn't make a difference so I started to do a code challenge next and then I notice one code challenge accepted my one wild card as correct example (SELECT * FROM users WHERE first_name LIKE "L%";) but the next one came along and then I used one wild card again example (SELECT * FROM products WHERE name LIKE "%t-shirt%";)but It said it was wrong so I put two wild cards example and then I passed the code challenge what is the difference between putting one wild card vs two wild cards?
Steven Parker
231,184 PointsGood explanation, Benjamin Larson — you should move your comment to an answer.
Miguel Nunez
3,266 PointsThanks man that helps alot now I have another question I'm taking a quiz and its asking a confusing question. If I wanted to return rows that match either conditions, which keyword would I use? SELECT <columns> FROM <table> WHERE <condition 1> <condition 2>;
1 Answer
Benjamin Larson
34,055 PointsMOVED TO ANSWERS (Steven Parker : not the first time I've made that mistake haha)
Hi Miguel,
Putting a wildcard before (WHERE name LIKE "%t-shirt") means that anything can occur before "t-shirt" is found in a string, but there can't be anything after it.
Conversely, putting the wildcard after (WHERE name LIKE "t-shirt%") means that anything can occur after that value is found, but "t-shirt" must come first in the string.
A wildcard before and after (WHERE name LIKE "%t-shirt%") means that anything can come before OR after. It should be noted that it's not a requirement for something to come before or after, meaning that "t-shirt" alone would satisfy the requirements.
To answer your second question: It sounds like the quiz is asking for the "OR" keyword in between the WHERE conditions.
Benjamin Larson
34,055 PointsBenjamin Larson
34,055 PointsHi Miguel,
Putting a wildcard before (WHERE name LIKE "%t-shirt") means that anything can occur before "t-shirt" is found in a string, but there can't be anything after it.
Conversely, putting the wildcard after (WHERE name LIKE "t-shirt%") means that anything can occur after that value is found, but "t-shirt" must come first in the string.
A wildcard before and after (WHERE name LIKE "%t-shirt%") means that anything can come before OR after. It should be noted that it's not a requirement for something to come before or after, meaning that "t-shirt" alone would satisfy the requirements.