🚨 $100K in Sight: Follow Bitcoin’s Final Push Live! TRACK NOW

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%';

DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

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%';