Like Operator

LIKE operator in mysql, is used in a WHERE clause to search for a specified pattern in a column.

Wildcard characters are used with the SQL LIKE operator.
(i) % :- A substitute for zero or more characters.
(ii) _ :- A substitute for a single character.

emp

In this above figure, we have employee table which has three fields emp_id, emp_name, emp_reporting_officer.

Example:- (i) Write a query, get the all employee which start from “emp”

mysql->SELECT emp_id, emp_name FROM `employee` where emp_name like “emp%”
like-operator

Example:- (ii) Write a query, get the all employee which ending from “A”

mysql->SELECT emp_id, emp_name FROM `employee` where emp_name like “%A”
like-operator2

Example:- (ii) Write a query, get the all employee which starting with any character, followed by “mpC”

mysql->SELECT emp_id, emp_name FROM `employee` where emp_name like ‘_mpC’
like_operator3