The LIKE operator lets you search for a pattern within a text column instead of matching an exact value. It's the tool you reach for whenever you need "contains," "starts with," or "ends with" logic in SQL — searching for all employees named something like "Jon" or finding every email address ending in a particular domain.

LIKE works together with two wildcard characters that stand in for unknown parts of the string: % for any number of characters (including zero), and _ for exactly one character.

The % Wildcard

The percent sign matches zero or more characters anywhere in that position. It's by far the most commonly used wildcard.

-- Employees whose name starts with "A"
SELECT name, department
FROM employees
WHERE name LIKE 'A%';

Result:

name | department
---------+-----------
Aisha | Marketing
Amir | Sales

You can place % at the start, the end, or both:

-- Ends with "son"
SELECT name FROM employees WHERE name LIKE '%son';

-- Contains "ar" anywhere
SELECT name FROM employees WHERE name LIKE '%ar%';

The _ Wildcard

The underscore matches exactly one character — useful when you know the length or structure of a value but not every character.

-- Four-letter names starting with "J"
SELECT name FROM employees WHERE name LIKE 'J___';

Result:

name
----
Jess

Case Sensitivity and NOT LIKE

Whether LIKE is case-sensitive depends on your database and its collation settings — PostgreSQL's default LIKE is case-sensitive (use ILIKE for case-insensitive matching), while MySQL's default is usually case-insensitive. Always check your specific setup rather than assuming.

To exclude a pattern instead of matching it, use NOT LIKE:

-- Everyone except Gmail addresses
SELECT name, email FROM employees WHERE email NOT LIKE '%@gmail.com';

LIKE is commonly combined with the row-filtering logic from the WHERE clause and the logical operators covered elsewhere in this course — for example, pairing a pattern match with an AND condition to narrow results further.