Other related articles:

Recently viewed articles:

SQL LIKE Keyword

We use the LIKE operator when we are not certain about the information we have on hand or we need to do search for some particular type of data. It allows to search using wildcard characters in a character field. A wildcard character doesn’t match a particular character but it can match any one character or any number of characters. For example, we need to find employees whose name start with letter ‘S’. The query would be like this:

 SELECT ename FROM emp

WHERE ename LIKE ‘S%’;

 There are two wildcard characters used in SQL:

  •  (%)  It finds one or more characters.
  • (_)  Matches one character.

The above statement produces these results:


In most of the cases, the LIKE operator is case-sensitive; that is the above query will find only names starting with capital S.

Now suppose we need to find employees whose names have letter ‘e’ at third place. The query would use both wildcard characters and will be like this:

SELECT ename FROM emp

WHERE ename LIKE ‘_ _e %’;

We can also use the NOT operator in combination  with LIKE operator, which produces a result where the character and wildcard combination is not found. For example, the following query will find all the employees whose name does not start with letter ‘S’:

 SELECT ename FROM emp

WHERE ename NOT LIKE ‘S%’;

The results would be reverse of the first query taken in this article as below: