WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL Wildcards


A wildcard character can be used to substitute for any other character(s) in a string.


The % wildcard can be used multiple times within the same pattern.

SQL Wildcard Characters

In SQL, wildcard characters are used with the SQL LIKE operator.

SQL wildcards are used to search for data within a table. 

With SQL, the wildcards are:

Wildcard Description
% A substitute for zero or more characters
_ A substitute for a single character
[charlist] Sets and ranges of characters to match
[^charlist]
or
[!charlist]
Matches only a character NOT specified within the brackets

Database

In this tutorial we will use the well-known database.

Below is a selection from the "Customers" table:

CustomerID FirstName Username Password Email Address
1

Mike Maier Porybouted ieZ6tei7ha MikeMaier@teleworm.us
2 Martina Jager Therstorted ejohKae5oh MartinaJager@jourrapide.com
3 Nadine Friedman Offece ieThodee0oo NadineFriedman@armyspy.com
4

Anna Bumgarner Laire1947 beeCh9thee. AnnaBumgarner@dayrep.com
5 Sabine Sanger Thertandet waexoof4Al SabineSanger@dayrep.com

Using the SQL % Wildcard

The following SQL statement selects all customers with a Email starting with "bar":

Example

SELECT * FROM Customers
WHERE Email LIKE 'bar%';

The following SQL statement selects all customers with a Email containing the pattern "uk": 

Example

SELECT * FROM Customers
WHERE Email LIKE '%uk%';

Using the SQL _ Wildcard

The following SQL statement selects all customers with a Email starting with any character, followed by "langu":

Example

SELECT * FROM Customers
WHERE Email LIKE '_langu';

The following SQL statement selects all customers with a Email starting with "J", followed by any character, followed by "k", followed by any character, followed by "on":

Example

SELECT * FROM Customers
WHERE City LIKE 'J_k_on';

Using the SQL [charlist] Wildcard

The following SQL statement selects all customers with a Email starting with "n", "p", or "m":

Example

SELECT * FROM Customers
WHERE City LIKE '[npm]%';

The following SQL statement selects all customers with a Email starting with "x", "y", or "z":

Example

SELECT * FROM Customers
WHERE City LIKE '[x-z]%';

The following SQL statement selects all customers with a Email NOT starting with "n", "p", or "q":

Example

SELECT * FROM Customers
WHERE Email LIKE '[!npq]%';

or

SELECT * FROM Customers
WHERE Email NOT LIKE '[npq]%';



Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.

welookups.com