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 Finding Data that Matches a Pattern

Miguel Nunez
Miguel Nunez
3,266 Points

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

Benjamin Larson
Benjamin Larson
34,055 Points

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.

Steven Parker
Steven Parker
220,634 Points

Good explanation, Benjamin Larson :+1: — you should move your comment to an answer. :arrow_heading_down:

Miguel Nunez
Miguel Nunez
3,266 Points

Thanks 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
Benjamin Larson
34,055 Points

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