English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Usage and examples of SQL LIKE keyword

SQL Keywords Reference

LIKE

Use the LIKE command in the WHERE clause to search for a specified pattern in the column.

You can use two wildcard characters LIKE:

  • % -Represents zero, one, or multiple characters

  • _-Represents a single character (Question mark (?) is used instead in MS Access)

The following SQL selects all customers whose CustomerName starts with 'a':

SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';

The following SQL selects all customers from CustomerName ending with 'a':

SELECT * FROM Customers
WHERE CustomerName LIKE '%a';

The following SQL selects all customers from CustomerName that have 'or' at any position:

SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';

The following SQL statement selects all CustomerName starting with 'a' and having a length of at least3number of characters of customers:

SELECT * FROM Customers
WHERE CustomerName LIKE 'a_%_%';

SQL Keywords Reference