← Back to Questions
SQL

What is the LIKE operator in SQL?

Learn What is the LIKE operator in SQL? with simple explanations, real-time examples, interview tips and practical use cases.

What is the LIKE Operator in SQL?

The LIKE operator in SQL is used to search for a specified pattern in a column.

In simple words:

LIKE helps perform pattern matching and partial searches in SQL queries.


Why LIKE is Important

Enterprise applications frequently require:

  • Search functionality
  • Partial text matching
  • Auto-suggestions
  • Filtering by keywords
  • Flexible user searches

LIKE helps:

  • Search incomplete text
  • Implement user-friendly filtering
  • Support dynamic search systems

Simple Real-Life Example

Think about:

  • Searching employees whose names start with "N"

Example

Naresh
Nikhil
Naveen

LIKE Internal Architecture

Read Column Value
        |
        v
Apply Pattern Matching
        |
        v
Pattern Matches?
     /           \
   Yes             No
    |               |
Return Row       Ignore Row

LIKE Syntax

SELECT column_name

FROM table_name

WHERE column_name LIKE pattern;

Important Wildcards Used with LIKE

Wildcard Meaning
% Represents zero or more characters
_ Represents exactly one character

1. Using % Wildcard

% represents:

  • Any number of characters

Example Table

Employee Name
Naresh
Nikhil
Rahul
Naveen

Example: Starts With N

SELECT employee_name

FROM employees

WHERE employee_name LIKE 'N%';

Result

Naresh
Nikhil
Naveen

Meaning

Find names:

  • Starting with N

Example: Ends With h

SELECT employee_name

FROM employees

WHERE employee_name LIKE '%h';

Result

Naresh
Rahul

Meaning

Find names:

  • Ending with h

Example: Contains ar

SELECT employee_name

FROM employees

WHERE employee_name LIKE '%ar%';

Result

Naresh

Meaning

Find names:

  • Containing "ar"

2. Using _ Wildcard

_ represents:

  • Exactly one character

Example

SELECT employee_name

FROM employees

WHERE employee_name LIKE '_a%';

Meaning

Find names:

  • Having "a" as second character

LIKE Query Flow

Read String
     |
     v
Compare with Pattern
     |
     v
Pattern Match?
 /             \
Yes             No
 |               |
Return Row     Ignore Row

LIKE vs = Operator

Feature LIKE =
Purpose Pattern matching Exact match
Wildcards Supported Not supported
Flexibility High Limited

Exact Match Example

SELECT *

FROM employees

WHERE employee_name = 'Naresh';

Pattern Match Example

SELECT *

FROM employees

WHERE employee_name LIKE 'N%';

LIKE with Numbers

LIKE can also work with:

  • Numeric values converted to text

Example

SELECT *

FROM products

WHERE product_code LIKE '10%';

Purpose

Find product codes:

  • Starting with 10

LIKE with Dates

LIKE can filter:

  • Date strings

Example

SELECT *

FROM orders

WHERE order_date LIKE '2026-05%';

Purpose

Find orders:

  • Placed in May 2026

NOT LIKE Operator

NOT LIKE is used to:

  • Exclude matching patterns

Example

SELECT employee_name

FROM employees

WHERE employee_name NOT LIKE 'N%';

Purpose

Retrieve employees:

  • Whose names do not start with N

LIKE with Multiple Conditions

SELECT *

FROM employees

WHERE employee_name LIKE 'N%'
OR employee_name LIKE 'R%';

Purpose

Retrieve employees:

  • Starting with N or R

Case Sensitivity in LIKE

Case sensitivity depends on:

  • Database configuration
  • Collation settings

Example

LIKE 'n%'

may behave differently across databases.


LIKE with ESCAPE Character

ESCAPE helps search:

  • Actual wildcard characters

Example

SELECT *

FROM products

WHERE product_name LIKE '%\%%'
ESCAPE '\';

Purpose

Find product names:

  • Containing % symbol

Performance Consideration

Efficient Pattern

LIKE 'N%'
  • Can use indexes efficiently

Less Efficient Pattern

LIKE '%ar%'
  • May require full table scan

Why?

Leading wildcard:

  • Prevents efficient index usage

LIKE Optimization Techniques

  • Use indexed columns
  • Avoid leading wildcards when possible
  • Use full-text search for large systems

LIKE vs Full-Text Search

Feature LIKE Full-Text Search
Performance Moderate High
Complex Search Limited Advanced
Best For Simple patterns Large text search systems

Real-Time Banking Example

Banking systems use LIKE for:

  • Customer name searches
  • Transaction reference filtering
  • Branch code matching

Example

WHERE customer_name LIKE 'Raj%'

Real-Time E-Commerce Example

E-commerce platforms use LIKE for:

  • Product searches
  • Category filtering
  • Brand suggestions

Example

WHERE product_name LIKE '%Laptop%'

Real-Time Learning Platform Example

Learning platforms use LIKE for:

  • Course searches
  • Student lookup
  • Technology filtering

Example

WHERE course_title LIKE '%Spring Boot%'

LIKE in Microservices

Microservices use LIKE for:

  • Search APIs
  • Autocomplete systems
  • Filtering services

Advantages of LIKE

  • Flexible pattern matching
  • Simple syntax
  • Useful for partial searches

Disadvantages of LIKE

  • Can be slow on large datasets
  • Leading wildcards reduce performance

Best Practices

  • Use indexed columns for searches
  • Avoid unnecessary leading wildcards
  • Use full-text search for complex search systems
  • Optimize frequently searched columns

Common Interview Mistake

Many developers think:

  • LIKE performs exact matching

Reality

LIKE performs:

  • Pattern-based matching

Related Learning Topics


Professional Interview Answer

The LIKE operator in SQL is used for pattern matching and partial text searches within query conditions. It works together with wildcard characters such as % and _ to search for values that match specific patterns. The % wildcard represents zero or more characters, while the _ wildcard represents exactly one character. LIKE is commonly used in search functionality, filtering systems, autocomplete features, customer lookup systems, and analytics applications. Enterprise applications such as banking systems, e-commerce platforms, learning portals, and microservices-based APIs heavily use the LIKE operator for flexible user-friendly searches and dynamic filtering operations.


Why Interviewers Like This Answer

  • Clearly explains pattern matching
  • Includes wildcard understanding
  • Shows performance awareness
  • Provides enterprise-level examples
  • Explains LIKE vs exact matching

Frequently Asked Questions

What is LIKE used for in SQL?

LIKE is used for pattern matching and partial searches.

What does % mean in LIKE?

% represents zero or more characters.

What does _ mean in LIKE?

_ represents exactly one character.

What is NOT LIKE in SQL?

NOT LIKE excludes rows matching a pattern.

Why can LIKE become slow?

Leading wildcards may prevent efficient index usage and cause full table scans.

Why this SQL question is important?

This interview question helps candidates understand real-time backend development concepts, practical problem solving, coding fundamentals, system design basics and production-ready application behavior.

Practice this question carefully for Java backend roles, Spring Boot developer interviews, microservices interviews, company interviews and full-stack developer preparation.

About the Author

Naresh Kumar is a Senior Java Backend Engineer with experience building enterprise applications using Java, Spring Boot, Microservices, Docker, Kubernetes and Cloud technologies.