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 alfredfutter@gmail.com secret1
2 atrujillo atrujillo@gmail.com secret2
3 moreno.antonio moreno.antonio@yahoo.com secret3
4 hardythomas thomas.hardy@gmail.com secret4
5 bergluns bergluns@gmail.com 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%';
Learn SQL
Introduction
Syntax
Data Types
Server Data Types
Commands
Commands List
Wildcards
Constraints
Aggregate Functions
Date Functions
Date Format
Injection
SQL Server Hosting
Views
Auto-incrementation
SQL Operators
AS
AND & OR
IN
BETWEEN
WHERE
GROUP BY
HAVING
ORDER BY
LIKE
NOT
NOT EQUAL
UNION
NULL
NOT NULL
DEFAULT
UNIQUE
FOREIGN KEY
PRIMARY KEY
CHECK
Indexes
ALTER TABLE
CREATE DATABASE
CREATE TABLE
DELETE
DROP
INSERT INTO SELECT
INSERT INTO
SELECT
SELECT DISTINCT
SELECT INTO
SELECT TOP
UPDATE
FULL OUTER JOIN
INNER JOIN
JOIN
LEFT JOIN
RIGHT JOIN
AVG()
COUNT
FIRST
LAST
MAX
MIN()
SUM()
LEN
UCASE
MID
NOW
ROUND
FORMAT
LOWER
CONVERT
ISNULL