Loading

LIKE Operator

  • The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
  •  It is often used with wildcard characters (% for any number of characters, _ for a single character)..
  • % (percentage): Zero, one or multiple characters.
  • _ (underscore): one or single character.

Example:

Let us create an Employee table with columns ID, EmpName, City, Salary 

ID

EmpName

City

Salary

1

Tom

ABC

7000

2

Enna

XYZ

5000

3

Genny

ABC

8000

If you want to list a city name starting with the letter A then we use the % query is

select * from employee
where City LIKE ‘A%’;

Output

ID

EmpName

City

Salary

1

Tom

ABC

7000

3

Genny

ABC

8000


If we want the employee records with the employee name that n is present in the second position then we use _

select * from employee 
where EmpName LIKE ‘_n%’;

Output:

ID

EmpName

City

Salary

2

Enna

XYZ

5000