Back to SQL Notes
Topic #87

SQL LIKE Operator

LIKE matches text against a pattern using wildcards — for partial or fuzzy string matching.

Syntax & Wildcards

WildcardMatches
%Any sequence of characters (including none)
_Exactly one character

Sample Table: employees

nameemail
Aman Sharmaaman@codingnowai.com
Riya Vermariya@gmail.com
Karan Mehtakaran@codingnowai.com

Examples

-- Names starting with "A"
SELECT name FROM employees WHERE name LIKE 'A%';

-- Names containing "an" anywhere
SELECT name FROM employees WHERE name LIKE '%an%';

-- Company emails only
SELECT name FROM employees WHERE email LIKE '%@codingnowai.com';

-- Exactly 4 characters, starting with "K"
SELECT name FROM employees WHERE name LIKE 'K___';

Output for 'A%': Aman Sharma.
Output for '%an%': Aman Sharma, Karan Mehta (both contain "an").

Case Sensitivity

MySQL's default collation is usually case-insensitive, so LIKE 'a%' and LIKE 'A%' often return the same rows. PostgreSQL's LIKE is case-sensitive by default — use ILIKE there for case-insensitive matching.

Practical Use Case

Search boxes ("find any product with 'phone' in the name"), filtering by email domain, or matching loosely-formatted codes.

Common Mistakes

  • Leading wildcard performance. LIKE '%something' (wildcard at the start) usually can't use a standard index efficiently, since the database can't jump to a starting point — it has to scan every row. LIKE 'something%' (wildcard only at the end) can use an index.
  • Forgetting to escape literal % or _ characters when they're part of the actual data you're searching for (use ESCAPE or a database-specific escape function)
  • Using LIKE '%value%' for a full-text search need — at scale, a dedicated full-text index is a better tool

Interview Relevance

Q: "Why is LIKE '%term' slower than LIKE 'term%'?" — tests whether you understand how B-tree indexes work, not just LIKE syntax.

Practice Question

Write a query to find all customers whose email ends in .edu.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

SQL LIKE Operator – FAQs

Quick answers about learning SQL LIKE Operator in SQL.

This free note from Coding Now Tech Institute explains SQL LIKE Operator in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including SQL LIKE Operator, is 100% free with no signup required.
With focused practice, most students grasp SQL LIKE Operator in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now