Chapter 2 · Lesson 3 of 3
Pattern Matching with LIKE
Match text patterns with LIKE and ILIKE using the % and _ wildcards, and find names that contain a given substring in a SQL challenge.
The LIKE operator matches text patterns using two wildcards:
% matches any sequence of characters (including none)
_ matches exactly one character
Examples:
WHERE name LIKE 'A%' -- names starting with A
WHERE name LIKE '%e' -- names ending with e
WHERE name LIKE '%li%' -- names containing "li"
WHERE name LIKE '_o%' -- names with "o" as the second letterIn DuckDB, LIKE is case-sensitive. DuckDB also supports ILIKE for case-insensitive matching:
WHERE name ILIKE '%alice%' -- matches Alice, ALICE, alice, etc.Sample data
This lesson loads the employees table (8 rows) into DuckDB in your browser with one click, so you can run every example without uploading anything.
Setup SQL for employees
CREATE OR REPLACE TABLE employees (
id INTEGER,
name VARCHAR,
department VARCHAR,
salary DECIMAL(10,2),
hire_date DATE
);
INSERT INTO employees VALUES
(1, 'Alice', 'Engineering', 95000, '2021-03-15'),
(2, 'Bob', 'Marketing', 72000, '2020-07-01'),
(3, 'Charlie', 'Engineering', 110000, '2019-01-10'),
(4, 'Diana', 'Sales', 68000, '2022-11-20'),
(5, 'Eve', 'Marketing', 78000, '2021-09-05'),
(6, 'Frank', 'Engineering', 102000, '2020-02-28'),
(7, 'Grace', 'Sales', 71000, '2023-04-12'),
(8, 'Hank', 'Marketing', 65000, '2022-06-30');Practice challenge
Find all employees whose name contains the letters li. Return name, ordered by name.
Hint: Use WHERE name LIKE '%li%' and ORDER BY name.
Run your query in the editor and the lesson checks the result automatically.
Lessons in Filtering Data
Narrow results to the rows you need with WHERE, combine conditions with AND and OR, and match text patterns with LIKE.
Related guides
SQL WHERE Clause Explained: Filtering Rows with AND, OR, and LIKE
Filtering is where SQL starts to feel useful: keep only the rows that answer your question, then combine conditions as your questions get sharper.
SQL String Functions for Cleaning Text: TRIM, LOWER, SPLIT_PART, and REGEXP_REPLACE
Exported text is messy. A handful of SQL string functions fix most of it: trim and lowercase values, join fields safely, split out parts, and strip characters with regex.
How to Flatten Nested JSON with SQL: Structs, Lists, and UNNEST
Nested JSON becomes STRUCT and LIST columns in DuckDB. Learn how to reach into structs, turn arrays into rows, and aggregate the flattened result.