Wildcards in SQL

SQL wildcards are put to substitute one or more characters in a string. Wildcards come in handy when we need to compare the strings and also aim to get the minute details.

Wildcards are put up with the LIKE operator and come in handy for solving complex queries.

For example, let us imagine a condition where we have a large amount of data available. And we want to find out details of all the people who lie in the age group 20 to 30 whose names start from A or N.

For resolving such complex queries we use wildcards.

Some of the most commonly used wildcards are as follows:

  1. Wildcards in MS Access
    Sr.No Representation Symbol Description
    1 * Stands for zero or more characters.
    2 ? Stands for a single character.
    3 [ ] Stands for a single character within the brackets.
    4 ! Stands for the characters not available in the bracket.
    5 Stands for a range of characters.
    6 # Stands for a single numeric character.
  2. Wildcards in SQL Server
    Sr.No Representation Symbol Description
    1 % Stands for zero or more characters.
    2 _ Stands for a single character.
    3 [ ] Stands for a single character specific to the brackets.
    4 ^ Stands for any character not in brackets.
    5 Stands for a range of characters.
Why do we Need Wildcards?

We use SQL wildcards when we need to search for complex data. This complex data could compromise strings or numerical with special characteristics.

Wildcards also come in handy when we want to speed up our querying process. The results are considerably fast when wildcards are in use.

We have already seen SQL Wildcards are put up with the LIKE operator.

Let us consider the usage and then we would discuss the examples:

Sr.No Usage with LIKE operator Description
1 WHERE columnName LIKE ‘a%’ Returns values which start with ‘a’.
2 WHERE columnName LIKE ‘%a’ Returns values which end with ‘a’.
3 WHERE columnName LIKE ‘%ab%’ Returns any value that has ‘ab’ in any position.
4 WHERE columnName LIKE ‘_a%’ Returns any value which has ‘a’ as the second character.
5 WHERE columnName LIKE ‘a_%_%’ Returns any value that starts with ‘a’ and is at least 3 characters in length.
6 WHERE columnName LIKE ‘a%b’ Returns any value which starts with ‘a’ and ends with ‘b’.


Copyright 1999- Ducat Creative, All rights reserved.

Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.