☰ Learn SQL Tutorial Menu
Pattern Matching with LIKE
Written by CSA mentors · 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 learning points for every lesson you finish.
Example
-- A ready-to-query practice database is loaded automatically before every run —
-- no CREATE TABLE needed. Available tables:
-- departments (id, name, location)
-- employees (id, first_name, last_name, email, department_id, job_title, salary, hire_date, manager_id)
-- customers (id, customer_name, city, country, signup_date)
-- products (id, product_name, category, price, stock_quantity)
-- orders (id, customer_id, employee_id, order_date, status)
-- order_items (id, order_id, product_id, quantity, unit_price)
SELECT * FROM employees WHERE department_id = 1;
