SQL – Wild Card Characters.
Table Of Contents:
- What Is A Wild Card Character?
- Syntax Of Wild Card Characters.
- Examples Of Wild CardCharacters.
(1) What Is A Wild Card Character?
- Wild card characters are special characters used for placeholder purposes.
- You can place one or more characters as per their nature in place of the wild card character.
![](https://www.praudyog.com/wp-content/uploads/2023/04/90.jpg)
(2) Syntax Of Wild Card Character.
Wildcard Characters in MS Access
![](https://www.praudyog.com/wp-content/uploads/2023/04/91-1024x394.jpg)
Wildcard Characters in SQL Server
![](https://www.praudyog.com/wp-content/uploads/2023/04/92-1024x271.jpg)
Some Examples:
![](https://www.praudyog.com/wp-content/uploads/2023/04/93-1024x310.jpg)
(3) Examples Of Wild Card Character.
Demo DataSet:
![](https://www.praudyog.com/wp-content/uploads/2023/04/94-1024x379.jpg)
Example-1: Using the % Wildcard: City starting with “ber”.
SELECT * FROM Customers
WHERE City LIKE 'ber%';
![](https://www.praudyog.com/wp-content/uploads/2023/04/95-1024x161.jpg)
Example-2: Using the % Wildcard: City containing the pattern “es”.
SELECT * FROM Customers
WHERE City LIKE '%es%';
![](https://www.praudyog.com/wp-content/uploads/2023/04/96-1024x401.jpg)
Example-3: Using the _ Wildcard: City starting with any character, followed by “ondon”.
SELECT * FROM Customers
WHERE City LIKE '_ondon';
![](https://www.praudyog.com/wp-content/uploads/2023/04/97-1024x297.jpg)
Example-4: Using the _ Wildcard: City starting with “L”, followed by any character, followed by “n”, followed by any character, followed by “on”.
SELECT * FROM Customers
WHERE City LIKE 'L_n_on';
![](https://www.praudyog.com/wp-content/uploads/2023/04/98-1024x302.jpg)
Example-5: Using the [charlist] Wildcard: City starting with “b”, “s”, or “p”.
SELECT * FROM Customers
WHERE City LIKE '[bsp]%';
![](https://www.praudyog.com/wp-content/uploads/2023/04/99-1024x267.jpg)
Example-6: Using the [charlist] Wildcard: City starting with “a”, “b”, or “c”.
SELECT * FROM Customers
WHERE City LIKE '[a-c]%';
![](https://www.praudyog.com/wp-content/uploads/2023/04/100-1024x235.jpg)
Example-7: Using the [!charlist] Wildcard: City NOT starting with “b”, “s”, or “p”.
SELECT * FROM Customers
WHERE City LIKE '[!bsp]%';
![](https://www.praudyog.com/wp-content/uploads/2023/04/101-1024x241.jpg)