Facebook Page Twitter Page LinkedIn Page
× SQL Tutorial SQL Advanced SQL Database SQL Resources


The SQL LIKE keyword is used in a WHERE clause to search for a specified pattern in a specified column. There are two wildcards which are often used in conjunction with the LIKE keyword.

  • % : represents zero, one or multiple characters.
  • _ : represents one character.

Note: In MS Access, asterisk (*) is used instead of percentage sign (%) and a question mark (?) is used instead of (_).

Syntax

The syntax for using LIKE keyword is given below:

SELECT column1, column2, ...
FROM table_name
WHERE column LIKE pattern;

The below table describes patterns which is used with LIKE keyword and uses (%) and (_).

PatternDescription
'J%'A value that start with "J".
'%n'A value that end with "n".
'%oh%'A value that have "oh" in any position.
'_o%'A value that have "o" in the second position.
'J_%'A value that start with "J" and have at least 2 characters.
'J%n'A value that start with "J" and ends with "n".

Example:

Consider a database tables called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To fetch all records from Employee table where Salary starts with 3 and ends with 0, the SQL query is:

    SELECT * FROM Employee
    WHERE Salary LIKE '3%0';
    
    /* My Access SQL code */
    SELECT * FROM Employee
    WHERE Salary LIKE '3*0';
    

    This will produce the result as shown below:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    4KimAmsterdam303100
    5RameshNew Delhi283000

❮ SQL Keywords