Use the SQL LIKE operator to search for a pattern in a column rather than an exact match.   This differs from the equals (=) comparison operator which requires an exact match. 

The general setup for using the LIKE operator is: 

SELECT column1, column2, … 
FROM   table1 
WHERE  column1 LIKE matchPattern 

With LIKE specify a pattern to partially match fields.  Here are some wild cards you can use to build match patterns. 

Common SQL Like Operator Wildcards

Note:  There are a couple of more wildcards you can use to specify ranges, but for now, we are going to focus on the most popular ones. 

Here are some example using the common patterns: 

a% Match any value beginning with a, such as aardvark! 
%and Match any value ending with and, such as sand. 
_b% Find any values that have b in the second position. 

SQL LIKE Operator Examples 

Let’s go over some examples to give you an appreciation of LIKE simplicity and power.  Consider the WHERE clause: 

WHERE FirstName LIKE ‘R%’ 

You may be wondering what is so special about that search as you could just as easily as written 

WHERE FirstName >= ‘R’ AND FirstName < ‘S’ 

to achieve the same result, but what about finding all names ending in the letter s?  There is no easy way to use the traditional comparison operators to do this, but it’s easily handled with LIKE: 

WHERE FirstName LIKE ‘%s’ 

Here is a query which finds every person whose first name ends in s.

SELECT FirstName , LastName FROM Person.Person WHERE FirstName LIKE '%s';
SELECT FirstName 
 , LastName 
FROM Person.Person 
WHERE FirstName LIKE '%s';

Try modifying the query to find every person whose first name begins with t and ends in s.

/*Write you answer here */
SELECT FirstName 
 , LastName 
FROM Person.Person 
WHERE FirstName LIKE 't%s';

You can also set up patterns to search for text within the middle of a value.  This is useful when you’re working with “dirty” or inconsistent data.  Here we’re looking for every employee classified as a technician:

To do so match using this pattern ‘%technician%’

SELECT NationalIDNumber , JobTitle , BirthDate FROM HumanResources.Employee WHERE jobtitle LIKE '%technician%';
SELECT NationalIDNumber 
 , JobTitle 
 , BirthDate 
FROM HumanResources.Employee 
WHERE jobtitle LIKE '%technician%';

Additional LIKE Resources 

To learn more about the LIKE operator, check out these useful resources: 

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}


Nothing is worse than, being excited to learn a new tool but not knowing where to start, wasting time learning the wrong features, and being overwhelmed .

But it doesn't have to be this way.

I'm Putting together a free email course to help you get started learning SQL Server.

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"b6728":{"name":"Main Accent","parent":-1},"03296":{"name":"Accent Low Opacity","parent":"b6728"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"b6728":{"val":"var(--tcb-skin-color-0)"},"03296":{"val":"rgba(17, 72, 95, 0.5)","hsl_parent_dependency":{"h":198,"l":0.22,"s":0.7}}},"gradients":[]},"original":{"colors":{"b6728":{"val":"rgb(47, 138, 229)","hsl":{"h":210,"s":0.77,"l":0.54,"a":1}},"03296":{"val":"rgba(47, 138, 229, 0.5)","hsl_parent_dependency":{"h":210,"s":0.77,"l":0.54,"a":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"dffbe":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default Palette","value":{"colors":{"dffbe":{"val":"var(--tcb-color-4)"}},"gradients":[]},"original":{"colors":{"dffbe":{"val":"rgb(19, 114, 211)","hsl":{"h":210,"s":0.83,"l":0.45}}},"gradients":[]}}]}__CONFIG_colors_palette__
Sign Up