< Sql Tutorial

Sql Wildcard Like

← Previous Next →


wildcard character can be used to substitute for any other character(s) in a string.


SQL Wildcard Characters

In SQL, wildcard characters are used with the SQL LIKE operator. SQL wildcards are used to search for data within a table. With SQL, the wildcards are:

Wildcard Description
% A substitute for zero or more characters
_ A substitute for a single character

Like clause

Like clause is used as condition in SQL query. Like clause compares data with an expression using wildcard operators. It is used to find similar data from the table.


Wildcard operators

There are two wildcard operators that are used in like clause.

  • Percent sign % : represents zero, one or more than one character.
  • Underscore sign _ : represents only one character.

Example of LIKE clause

Consider the following Student table.

s_id s_Name age
101 Adam 15
102 Alex 18
103 Abhi 17
SELECT * from Student where s_name like 'A%';

The above query will return all records where s_name starts with character 'A'.

s_id s_Name age
101 Adam 15
102 Alex 18
103 Abhi 17

Example

SELECT * from Student where s_name like '_d%';

The above query will return all records from Student table where s_name contain 'd' as second character.

s_id s_Name age
101 Adam 15

Example

SELECT * from Student where s_name like '%x';

The above query will return all records from Student table where s_name contain 'x' as last character.

s_id s_Name age
102 Alex 18
← Previous Next →