Use of SQL LIKE Operator. The following SQL commands show how to use LIKE Operator for querying on string data.
Patterns:
LIKE Operator |
Description |
LIKE 'a%' |
start with "a" |
LIKE '%a' |
end with "a" |
LIKE '%or%' |
have "or" in any position |
LIKE '_r%' |
have "r" in the second position |
LIKE 'a__%' |
start with "a" and are at least 3 characters in length |
LIKE 'a%o' |
start with "a" and ends with "o" |
SQL LIKE Syntax:
SELECT column, column, ...
FROM table_name
WHERE column LIKE pattern;
Examples:
SELECT * FROM employees
WHERE name LIKE 'a%';
SELECT * FROM employees
WHERE name LIKE '%a';
SELECT * FROM employees
WHERE name LIKE '%or%';
SELECT * FROM employees
WHERE name LIKE '_r%';
SELECT * FROM employees
WHERE name LIKE 'a__%';
SELECT * FROM employees
WHERE name LIKE 'a%o';
SELECT * FROM employees
WHERE name LIKE 'a%';