w3resource

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.

Relational Algebra Tree:

Relational Algebra Tree: [charlist] wildcards.

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.

Relational Algebra Tree:

Relational Algebra Tree: Sql [^charlist] wildcards.

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.

Relational Algebra Tree:

Relational Algebra Tree: Sql [!charlist] wildcards.

See our Model Database

Check out our 1000+ SQL Exercises with solution and explanation to improve your skills.



Follow us on Facebook and Twitter for latest update.