SQL
LIKE Operator

LIKE operator is used to search a Matching pattern in a column it will returns the matching values.

Like I am searching for a student name or city name but I forget the exact spellings of that city or student in such kind of cases LIKE operator is very helpful.

Operators of LIKE

Below are some most important and basic commands of SQL.

OperatorDescription
WHERE StudentName LIKE ‘a%’Finds any values that start with “a”
WHERE StudentName LIKE ‘%a’Finds any values that end with “a”
WHERE StudentName LIKE ‘%or%’Finds any values that have “or” in any position
WHERE StudentName LIKE ‘_r%’Finds any values that have “r” in the second position
WHERE StudentName LIKE ‘a_%_%’Finds any values that start with “a” and are at least 3 characters in length
WHERE StudentName LIKE ‘a%o’Finds any values that start with “a” and ends with “o”
WHERE StudentName LIKE ‘%a’Finds any values that end with “a”

Examples

This example returns us all the student names that ends with a.


	SELECT * FROM student
	WHERE StudentName LIKE '%a';

This example returns us all the student names that starts with a.


	SELECT * FROM student
	WHERE StudentName  LIKE 'a%';

This example returns us all the student names that starts with s and ends with a.


	SELECT * FROM student
	WHERE StudentName  LIKE 's%a';