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

Question about relation between LIKE and %

Hello, I'm just a little confused on what LIKE and the % does. I know that "%text%" will search through everything with text, so what's the need for the LIKE clause?


1 Answer

Leandro Botella Penalva
Leandro Botella Penalva
17,618 Points

Hi Max,

LIKE is an operator that tells to find something that matches the pattern between quotes you write after the LIKE. The "%" character is a wildcard that represents that where is placed should be zero, one or multiple characters. There is another wildcard character, the "_" which represents that where is placed should be only one character.

For example if you have: LIKE 'c%' you are finding something that starts with "c" and after that whatever (remember that % means 0, 1 or multiple characters), and with LIKE '_c%' you are finding something that starts with any character (remember that _ means just 1 character), the second character must be a "c" and then whatever.

And with the example of LIKE '%text%' you will find anything that starts, contains or ends with the word "text".


Thanks for responding, I think I got confused with past experience. I recall seeing something like

SELECT * FROM table WHERE something = "%text%";

So I was wondering what does adding the LIKE do to it. But it seems like that you need the LIKE keyword.

Anyways, thanks.