SQL LIKE clause

LIKE clause is used in the condition in SQL query with the WHERE clause. LIKE clause compares data with an expression using wildcard operators to match pattern given in the condition.


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 a single character.

Example of LIKE clause

Consider the following Student table.

s_ids_Nameage
101Adam15
102Alex18
103Abhi17
SELECT * FROM Student WHERE s_name LIKE 'A%';

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

s_ids_Nameage
101Adam15
102Alex18
103Abhi17


Using _ and %

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_ids_Nameage
101Adam15

Using % only

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_ids_Nameage
102Alex18