0% found this document useful (0 votes)
39 views

SQL Wildcard Characters

Uploaded by

Anum Masood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

SQL Wildcard Characters

Uploaded by

Anum Masood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SQL Wildcards

‹ Previous Next ›

SQL Wildcard Characters


A wildcard character is used to substitute one or
more characters in a string.

Wildcard characters are used with the LIKE


operator. The LIKE operator is used in a WHERE
clause to search for a specified pattern in a
column.

Example Get your own SQL Server

Return all customers that starts with the letter 'a':

SELECT * FROM Customers


WHERE CustomerName LIKE 'a%';

Try it Yourself »

Wildcard Characters
Symbol Description
Symbol Description

% Represents zero or more characters

_ Represents a single character

[] Represents any single character


within the brackets *

^ Represents any character not in the


brackets *

- Represents any single character


within the specified range *

{} Represents any escaped character


**

 Tutorials  Exercises  Certificates  Services  Search...


* Not supported in PostgreSQL and MySQL
HTML CSS JAVASCRIPT SQLdatabases.
PYTHON JAVA PHP HOW TO W3.CSS C

SQL Tutorial ** Supported only in Oracle databases.

SQL HOME
SQL Intro
SQL Syntax Demo Database
SQL Select
Below is a selection from the Customers table
SQL Select Distinct
used in the examples:
SQL Where
SQL Order By
CustomerID CustomerName ContactName
SQL And
SQL Or 1 Alfreds Maria Anders
SQL Not Futterkiste
SQL Insert Into
2 Ana Trujillo Ana Trujillo
SQL Null Values
Emparedados y
SQL Update
helados
SQL Delete
SQL Select Top 3 Antonio Moreno Antonio
SQL Aggregate Functions Taquería Moreno
SQL Min and Max
4 Around the Horn Thomas Hardy
SQL Count
SQL Sum
SQL Avg 5 Berglunds Christina
snabbköp Berglund
SQL Like snabbköp Berglund

SQL Wildcards
SQL In
SQL Between
SQL Aliases
SQL Joins
SQL Inner Join
SQL Left Join
SQL Right Join
SQL Full Join
SQL Self Join
SQL Union
SQL Group By 1. SQL Database Commands
SQL Having
SQL Exists
Best Database Managemen
SQL Any, All 2.
Software
SQL Select Into
SQL Insert Into Select
SQL Case
3. Online SQL Courses
SQL Null Functions
SQL Stored Procedures
SQL Comments
SQL Operators

SQL Database Using the % Wildcard


SQL Create DB
The % wildcard represents any number of
SQL Drop DB characters, even zero characters.
SQL Backup DB
SQL Create Table
SQL Drop Table Example
SQL Alter Table
SQL Constraints Return all customers that ends with the pattern
SQL Not Null 'es':

SQL Unique
SELECT * FROM Customers
SQL Primary Key
WHERE CustomerName LIKE '%es';
SQL Foreign Key
SQL Check
Try it Yourself »
SQL Default
SQL Index
SQL Auto Increment
SQL Dates
SQL Views Example
SQL Injection
Return all customers that contains the pattern
SQL Hosting
'mer':
SQL Data Types
SELECT * FROM Customers
SQL References WHERE CustomerName LIKE '%mer%';
SQL Keywords 
MySQL Functions  Try it Yourself »
SQL Server Functions 
MS Access Functions 
SQL Quick Ref

SQL Examples Using the _ Wildcard


SQL Examples The _ wildcard represents a single character.
SQL Editor
It can be any character or number, but each _
SQL Quiz
represents one, and only one, character.
SQL Exercises
SQL Server
SQL Bootcamp
Example
SQL Certificate
Return all customers with a City starting with
any character, followed by "ondon":

SELECT * FROM Customers


WHERE City LIKE '_ondon';

Try it Yourself »

Example
Return all customers with a City starting with
"L", followed by any 3 characters, ending with
"on":

SELECT * FROM Customers


WHERE City LIKE 'L___on';
WHERE City LIKE 'L___on';

Try it Yourself »

Using the [] Wildcard


The [] wildcard returns a result if any of the
characters inside gets a match.

Example
Return all customers starting with either "b", "s",
or "p":

SELECT * FROM Customers


WHERE CustomerName LIKE '[bsp]%';

Try it Yourself »

Using the - Wildcard


The - wildcard allows you to specify a range of
characters inside the [] wildcard.

Example
Return all customers starting with "a", "b", "c",
"d", "e" or "f":

SELECT * FROM Customers


WHERE CustomerName LIKE '[a-f]%';

Try it Yourself »
Try it Yourself »

Combine Wildcards
Any wildcard, like % and _ , can be used in
combination with other wildcards.

Example
Return all customers that starts with "a" and are
at least 3 characters in length:

SELECT * FROM Customers


WHERE CustomerName LIKE 'a__%';

Try it Yourself »

Example
Return all customers that have "r" in the second
position:

SELECT * FROM Customers


WHERE CustomerName LIKE '_r%';

Try it Yourself »

Without Wildcard
If no wildcard is specified, the phrase has to have
an exact match to return a result.

Example
Example
Return all customers from Spain:

SELECT * FROM Customers


WHERE Country LIKE 'Spain';

Try it Yourself »

Microsoft Access
Wildcards
The Microsoft Access Database has some other
wildcards:

Symbol Description Example

* Represents zero bl* finds bl, black,


or more blue, and blob
characters

? Represents a h?t finds hot, hat,


single character and hit

[] Represents any h[oa]t finds hot


single character and hat, but not
within the hit
brackets

! Represents any h[!oa]t finds hit,


character not in but not hot and
the brackets hat

- Represents any c[a-b]t finds cat


single character and cbt
within the
specified range

# Represents any 2#5 finds 205,


single numeric 215, 225, 235,
character 245, 255, 265,
275, 285, and 295

Test Yourself With


Exercises

Exercise:
Select all records where the second letter of
the City is an "a".

SELECT * FROM Customers


WHERE City LIKE ' %';

Submit Answer »

Start the Exercise

‹ Previous Next ›

W3schools
Pathfinder

Track
your Sign Up Log in
progress

You might also like