SQL – Wild Card Characters.

Table Of Contents:

  1. What Is A Wild Card Character?
  2. Syntax Of Wild Card Characters.
  3. 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.

(2) Syntax Of Wild Card Character.

Wildcard Characters in MS Access

Wildcard Characters in SQL Server

Some Examples:

(3) Examples Of Wild Card Character.

Demo DataSet:

Example-1: Using the % Wildcard: City starting with “ber”.

SELECT * FROM Customers
WHERE City LIKE 'ber%';

Example-2: Using the % Wildcard: City containing the pattern “es”.

SELECT * FROM Customers
WHERE City LIKE '%es%';

Example-3: Using the _ Wildcard: City starting with any character, followed by “ondon”.

SELECT * FROM Customers
WHERE City LIKE '_ondon';

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';

Example-5: Using the [charlist] Wildcard: City starting with “b”, “s”, or “p”.

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

Example-6: Using the [charlist] Wildcard: City starting with “a”, “b”, or “c”.

SELECT * FROM Customers
WHERE City LIKE '[a-c]%';

Example-7: Using the [!charlist] Wildcard: City NOT starting with “b”, “s”, or “p”.

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

Leave a Reply

Your email address will not be published. Required fields are marked *