LIKE Operator

What is the LIKE Operator?

The LIKE operator is used in SQL to search for a specific pattern in a column. It allows you to match text using wildcards instead of exact values.

Syntax

SELECT column1, column2
FROM table_name
WHERE column_name LIKE pattern;
  • column_name – The column you want to search in
  • pattern – The text pattern to match

Wildcards Used with LIKE

  1. % – Represents zero, one, or multiple characters
    • Example: 'A%' matches any value starting with A
    • Example: '%son' matches any value ending with son
  2. _ – Represents a single character
    • Example: 'A_n' matches ‘Ann’, ‘Aen’, etc.

Examples

Example 1: Find names starting with “J”

SELECT name
FROM students
WHERE name LIKE 'J%';

Example 2: Find emails ending with “@gmail.com”

SELECT email
FROM users
WHERE email LIKE '%@gmail.com';

Example 3: Find words with “ar” in the middle

SELECT product_name
FROM products
WHERE product_name LIKE '%ar%';

Example 4: Find three-letter names starting with “A”

SELECT name
FROM employees
WHERE name LIKE 'A__';

Key Points to Remember

  • LIKE is case-insensitive in some databases and case-sensitive in others.
  • % can be used at the beginning, end, or both sides of the pattern.
  • _ is useful when you want to match a single unknown character.
  • For exact matches, use = instead of LIKE.
Home » SQL Foundations Program (SQL-101) > Filtering & Conditions > LIKE Operator