Wildcard Operator in SQL

Shristi
Shristi
Nov 6 · 2 min read

Wildcard operator is the SQL operator which work in conjunction with other operators to look for a particular pattern

This operator is always used with Like operator in SQL

The Like operator is used in where clause to search for a pattern in the specified column.

Wildcard operators are as follows:

1.%(percent sign)

This percent sign is used to match one or more characters.

It can also be used with [charlist] these square brackets it is used to define a list of character so that we can search for for tone or more character in the column at time

[^charlist] or [!charlist] these are used to define a list of character which should not match

2. _(underscore)

It is used to search for only one character.

This is also used to specify the position of the letter.

a)SELECT * FROM Employee

WHERE Name LIKE ‘x% ’

It is used to search for the name which start letter ‘x’.

b)SELECT * FROM Employee

WHERE Name LIKE ‘% x’

It will return the name which end with letter ‘x’

c)SELECT * FROM Employee

WHERE Name LIKE ‘%x% ’

To find the name with letter ‘x’ at any position.

d)SELECT * FROM Employee

WHERE Name LIKE ‘_x% ’

To find a name with letter ‘x’ at second position.

e)SELECT * FROM Employee

WHERE Name LIKE ‘[abc]% ’

To find a name which starts any of the following letters inlist a,b, or c

f)SELECT * FROM Employee

WHERE Name LIKE ‘[!xyz]% ’

It is used to find a name which does not starts with letter x, y, or z.

If you are new to SQL Server start with the following must-watch video: -

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade