
Quick Contact
SQL & My SQL Tutorial
- INTRODUCATION
- What is SQL?
- SQL Microsoft
- SQL Management Tools
- SQL Developer
- Docker Commands
- Composite Key in SQL
- SQL Constraints
- Transactions in SQL Server
- SQL Server Data Types
- SQL Update Join
- SQL Operators
- SQL Clauses
- SQL Commands
- SQL Alter Command
- Distinct Keyword in SQL
- SQL Statements
- SQL Index
- SQL Injections
- Wildcards in SQL
- Alter and Truncate Command in SQL
- SQL Null Functions – ISNULL, IFNULL, Combine, & NULLIF
- SQL Sequence
- How to Find Duplicate Records in SQL
- Primary and Foreign Key in SQL with Examples
- COUNT Function
- SUM Function in SQL
- Dynamic SQL
- Database Tuning
- Pseudocolumn in Oracle SQL
- Triggers in SQL
- Embedded SQL in DBMS
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:
-
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. -
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’. |