Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
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

Practice SQL Exercises

Want to improve the above article? Contribute your Notes/Comments/Examples through Disqus.



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3