Black friday

Save big!

All courses under $5 - for a limited time!

Code has been added to clipboard!

SQL LIKE Operator Syntax and Examples

Reading time 2 min
Published Aug 9, 2017
Updated Oct 10, 2019

SQL LIKE Operator: Main Tips

  • The operator LIKE is used inside a WHERE clause for searching specific patterns in columns.
  • The operator LIKE is often used for search queries using keywords.

Syntax of SQL LIKE Operator

Example
SELECT * FROM users WHERE email LIKE '%gmail%';

SQL LIKE Operator: Demo Database

In this example we are using a basic SQL database.

Right here we have a section from the table called "Users":

ID Username Email Password
1 alfredfutter [email protected] secret1
2 atrujillo [email protected] secret2
3 moreno.antonio [email protected] secret3
4 hardythomas [email protected] secret4
5 bergluns [email protected] secret5

SQL LIKE Operator %: Examples

This statement will select every row from the table called "users", where email starts with an "a":

Example
SELECT * FROM users WHERE email LIKE 'a%';

Note: Using "%" is for defining wildcards and can be used on either end of the keyword. In these examples, "%" on both sides means that the keyword may be a part of a longer text or word; placed on the left of the keyword it means that the keyword may be on the ending of another word; placed on the right of the keyword it means that the keyword may be in the beginning of another word.

This statement will select every row from the table called "users", where username ends with an "o":

Example
SELECT * FROM users WHERE username LIKE '%o';

This statement will select every row from the table called "users", where email contains the word "yahoo":

Example
SELECT * FROM users WHERE email LIKE '%yahoo%';

The keyword NOT reverses the logic, making the statement select the rows that do NOT contain the keyword you specified.

This statement will select every row from the table called "Users", where email does NOT contain the word "gmail":

Example
SELECT * FROM users WHERE email NOT LIKE '%gmail%';