SQL [charlist] wildcards
[charlist] wildcards
The [charlist] WILDCARDS are used to represent any single character within a charlist.
The [^charlist] and [!charlist] WILDCARDS is used to represents any single character not in the charlist.
Example:
Sample table: agents
To get all rows from the table 'agents' with following condition -
1. the 'agent_name' must begin with the letter 'a' or 'b' or 'i'
the following sql statement can be used :
SELECT *
FROM agents
WHERE agent_name LIKE '[abi]%';
Relational Algebra Expression:
![Relational Algebra Expression: [charlist] wildcards.](https://www.w3resource.com/w3r_images/sql-charlist-wildcards-operator-exercise-relational-algebra.png)
Relational Algebra Tree:
![Relational Algebra Tree: [charlist] wildcards.](https://www.w3resource.com/w3r_images/sql-charlist-wildcards-operator-exercise-relational-algebra-tree-diagram.png)
Sql [^charlist] wildcards
Sample table: agents
To get all rows from the table 'agents' with following condition -
1.the 'agent_name' must not begin with the letter 'a' or 'b' or 'i',
the following sql statement can be used :
SELECT *
FROM agents
WHERE agent_name LIKE '[^abi]%';
Relational Algebra Expression:
![Relational Algebra Expression: Sql [^charlist] wildcards.](https://www.w3resource.com/w3r_images/sql-^-charlist-wildcards-operator-exercise-relational-algebra.png)
Relational Algebra Tree:
![Relational Algebra Tree: Sql [^charlist] wildcards.](https://www.w3resource.com/w3r_images/sql-^-charlist-wildcards-operator-exercise-relational-algebra-tree-diagram.png)
Sql [!charlist] wildcards
Sample table: agents
To get all rows from the table 'agents' with following condition -
1.the 'agent_name' must not begin with the letter 'a' or 'b' or 'i',
the following sql statement can be used :
SELECT *
FROM agents
WHERE agent_name LIKE '[!abi]%';
Relational Algebra Expression:
![Relational Algebra Expression: Sql [!charlist] wildcards.](https://www.w3resource.com/w3r_images/sql-!-charlist-wildcards-operator-exercise-relational-algebra.png)
Relational Algebra Tree:
![Relational Algebra Tree: Sql [!charlist] wildcards.](https://www.w3resource.com/w3r_images/sql-!-charlist-wildcards-operator-exercise-relational-algebra-tree-diagram.png)
Check out our 1000+ SQL Exercises with solution and explanation to improve your skills.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join