WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL LIKE Operator


The LIKE operator is used to search for a specified pattern in a column in the WHERE clause.


SQL LIKE operator

The LIKE operator is used to search for a specified pattern in a column in the WHERE clause.

SQL LIKE syntax

SELECT column_name (s)
FROM table_name
WHERE column_name LIKE pattern ;


Demo database

In this tutorial, we will use the welookups sample database.

Here is the data from the "Websites" table:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/ | 1     | USA     |
| 2  | Indiatimes          | https://www.Indiatimes.com/| 13    | IN            |
| 3  | zomato      | http://www.zomato.com/ | 4689  | IN       |
| 4  | indiamart          | http://indiamart.com/      | 20    | IN            |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
| 7  | stackoverflow | http://stackoverflow.com/|   0 | IND     |
+----+---------------+---------------------------+-------+---------+


SQL LIKE operator example

The following SQL statement selects all customers whose name starts with the letter "G":

Example

SELECT * FROM Websites
WHERE name LIKE 'G%';

Execution output´╝Ü

Tip: The "%" symbol is used to define wildcards (default letters) before and after the pattern. You will learn more about wildcards in the next chapter.

The following SQL statement selects all customers whose name ends with the letter "k":

Example

SELECT * FROM Websites
WHERE name LIKE '%k';

Execution output:

The following SQL statement selects all customers whose name contains the pattern "oo":

Examples

SELECT * FROM Websites
WHERE name LIKE '%oo%';

Execution output:

By using the NOT keyword, you can select records that do not match the pattern.

The following SQL statement selects all customers whose name does not contain the pattern "oo":

Examples

SELECT * FROM Websites
WHERE name NOT LIKE '%oo%';