☰ Learn SQL Tutorial Menu
Pattern Matching with LIKE
Written by Faisal Adnan · Updated 16 Sept 2026 · 3 min read
LIKE lets you search for text that partially matches a pattern, using two wildcards.
The wildcards
| Wildcard | Meaning |
|---|---|
% | any number of characters (including zero) |
_ | exactly one character |
Examples
-- Names starting with 'A'
SELECT first_name FROM employees WHERE first_name LIKE 'A%';
-- Names ending in 'a'
SELECT first_name FROM employees WHERE first_name LIKE '%a';
-- Names containing 'ha' anywhere
SELECT first_name FROM employees WHERE first_name LIKE '%ha%';
-- Exactly 3 letters
SELECT first_name FROM employees WHERE first_name LIKE '___';
Case sensitivity
This is one of the few places engines genuinely differ: LIKE is case-insensitive in SQLite and SQL Server by default, but case-sensitive in PostgreSQL. PostgreSQL provides ILIKE for a case-insensitive match:
-- PostgreSQL only
SELECT * FROM customers WHERE city ILIKE 'lahore';
Negation
SELECT first_name FROM employees WHERE first_name NOT LIKE 'A%';
Escaping literal % or _
If you need to search for an actual percent sign or underscore, escape it (syntax varies slightly by engine, but the common approach is):
SELECT * FROM products WHERE product_name LIKE '%50\%%' ESCAPE '\\';
Open the Code Playground, pick any SQL engine (SQLite, PostgreSQL, MySQL, or SQL Server), and paste these queries in directly — the practice database above is already loaded for you, every time.
Lesson 7 of 27
Sign in to track your progress and earn XP for every lesson you finish.
Practice tip: the built-in code runner is being upgraded. Until it is back, copy the examples into any SQL or Python tool you have (for example SQLite, PostgreSQL, MySQL, SQL Server or a free online editor) and run them there. You can keep reading and earning XP here.
