SQL like operator

The SQL like operator works with the “WHERE” clause. The SQL like statement is used to extract some kind of data from the database. The LIKE operator searches the string and extracts the data when it matches.

There are 2 types of wildcards work with LIKE operator, one is percent (%) and the other is underscore (_). Let’s know how to use like operator in SQL.

SQL Like Operator

Below you can see SQL LIKE operators have been used with both wildcards, and you will find out what the “like statement” means.

WHERE name LIKE ‘a%’Which starts with name (a)
WHERE name LIKE ‘%g’Which ends with name (g)
WHERE name LIKE ‘%kl%’The name (kl) comes in between
WHERE name LIKE ‘_x%’The name whose second character is (x)
WHERE name LIKE ‘t%v’The name that starts with (t) and ends with (v)
WHERE name LIKE ‘__j%’The name whose third character is (j)
WHERE salary LIKE ‘5%’The salary that starts at (5)
WHERE salary LIKE ‘[253]%Only salary that start with 2, 5 and 3
WHERE name LIKE ‘[a-h]%’Names between a to h
WHERE name LIKE ‘[aht]%’Only names that start with a, h and t
/ ***** Which starts with name a ***** /

SELECT * FROM Employees
WHERE name LIKE 'a%';

/ ***** Which ends with name g ***** /

SELECT * FROM Employees
WHERE name LIKE '%g';

/ ***** The name kl comes in between ***** /

SELECT * FROM Employees
WHERE name LIKE '%kl%';

/ ***** Which starts with name hi ***** /

SELECT * FROM Employees
WHERE name LIKE 'hi%';

/ ***** Only names that start with a, h and t character ***** /

SELECT * FROM Employees
WHERE name LIKE '[aht]%';

/ ***** Names between a to h ***** /

SELECT * FROM Employees
WHERE name LIKE '[a-h]%';

/ ***** The name whose second character  is x ***** /

SELECT * FROM Employees
WHERE name LIKE '_x%';

/ ***** The name that starts with t and ends with v ***** /

SELECT * FROM Employees
WHERE name LIKE 't%v';

/ ***** The name whose third character is j ***** /

SELECT * FROM Employees
WHERE name LIKE '__j%';

/ ***** The salary that starts at 5 ***** /

SELECT * FROM Employees
WHERE salary LIKE '5%';

/ ***** Only salary that start with 2, 5 and 3 ***** /

SELECT * FROM Employees
WHERE salary LIKE '[253]%';

/ ***** Single column data which starts with name ef ***** /

SELECT name FROM Employees
WHERE name LIKE 'ef%';

/ ***** 2 column data which starts with name wx ***** /

SELECT name, salary FROM Employees
WHERE name LIKE 'wx%' LIMIT 5;
EmployeeIDNameAgeSalaryJoinDate
1abc20200019-2-2020
2efg30540010-2-2019
3hij40560016-4-20015
4klm50360010-5-2004
5nop60240015-2-2009
6qrs70570010-6-2018
7tuv80800025-12-2016
8wxy90980010-7-2005
9zzz100520030-9-2014

SQL Not Like

You can use the SQL “Not” Like operator for the record you do not want to show. The “Not” Like operator will not pick up your record for which you set your command. It will search your query and you will get the result after the record matches.

/ ***** Which starts with name a ***** /

SELECT * FROM Employees
WHERE name Not LIKE 'a%';

/ ***** Which ends with name g ***** /

SELECT * FROM Employees
WHERE name NOT LIKE '%g';

/ ***** The name kl comes in between ***** /

SELECT * FROM Employees
WHERE name NOT LIKE '%kl%';


/ ***** Which starts with name hi ***** /

SELECT * FROM Employees
WHERE name NOT LIKE 'hi%';

/ ***** The name whose second character  is x ***** /

SELECT * FROM Employees
WHERE name NOT LIKE '_x%';

/ ***** The name that starts with t and ends with v ***** /

SELECT * FROM Employees
WHERE name NOT LIKE 't%v';


/ ***** The salary that starts at 5 ***** /

SELECT * FROM Employees
WHERE salary NOT LIKE '2%';

SQL Keywords

We have some keywords of SQL available, which are used most commonly.
Let’s know what those keywords are and what they mean.

NoKeywordsDescription
1CREATEIt is used to create a database and table
2CREATE DATABASEIt is used to create a database only
3CREATE TABLEIt is used to create a table
4DELETEIt is used to delete record from the table
5DROPIt is used to delete a column, database, and table
6DROP COLUMNIt is used to delete a column in the table
7DROP TABLEIt is used to delete a table
8FOREIGN KEYIt is used to join two tables together
9JOINIt is used to join the tables
10UPDATEIt is used to update the record in the table

Related: 17 most useful examples of SQL order by