1. SQL basics: ask a table a question
1.5 LIKE and IN: match a pattern or a list
Highlights & notes
Select lesson text to highlight it, or tap Add note.
Bookmarks
Bookmark a lesson to see it here.
Sometimes you do not know the exact value. You remember that a name ends with a, or a product starts with M. LIKE matches text against a pattern.
%stands for any number of characters, even none_stands for exactly one character'M%'starts with M ·'%a'ends with a ·'%ou%'contains ou
IN checks a value against a list. product IN ('Mouse', 'Keyboard') is a short way to write two conditions joined by OR.
A pattern that starts with %, like '%son', makes the database read every row. On big tables prefer patterns that start with real letters, like 'Jo%'.
Names that end with a
The % can stand for any letters before the final a.
SQL
SELECT name, cityFROM customersWHERE name LIKE '%a';
Rows at this step
name | city ------+------ Asha | Noida Meera | Pune Zoya | NULL
Quick check
Which pattern matches every product that starts with M?
One of a list
IN replaces a chain of ORs.
SQL
SELECT id, product, amountFROM ordersWHERE product IN ('Mouse', 'Keyboard')ORDER BY id;
Rows at this step
id | product | amount ----+----------+------- 102 | Mouse | 700 103 | Keyboard | 1500 106 | Mouse | 650 108 | Keyboard | NULL
Quick check
status IN ('pending', 'cancelled') means the same as…
Practice in SQL ✓ Solved
Show the id and product of the orders whose product starts with M.
Tables you can query: customers, orders
customers id | name | city ---+-------+------ 1 | Asha | Noida 2 | Ravi | Delhi 3 | Meera | Pune 4 | Kabir | Noida 5 | Zoya | NULL orders id | customer_id | product | amount | status | order_date ----+-------------+----------+--------+-----------+----------- 101 | 1 | Laptop | 55000 | delivered | 2026-01-05 102 | 2 | Mouse | 700 | delivered | 2026-01-06 103 | 1 | Keyboard | 1500 | delivered | 2026-01-09 104 | 3 | Monitor | 12000 | cancelled | 2026-01-12 105 | 2 | Laptop | 52000 | delivered | 2026-01-15 106 | 4 | Mouse | 650 | pending | 2026-01-18 107 | 1 | Monitor | 11500 | delivered | 2026-01-20 108 | 3 | Keyboard | NULL | pending | 2026-01-22
Expected output
id | product ----+-------- 102 | Mouse 104 | Monitor 106 | Mouse 107 | Monitor
Reference solution
SELECT id, product
FROM orders
WHERE product LIKE 'M%';
Question 1 · Easy
In a LIKE pattern, what does % stand for?
Question 2 · Medium
Which names match LIKE '_avi'?
Question 3 · Hard
How do you find the customers whose city is NOT Noida or Delhi?
Key takeaways
LIKE matches text patterns: % is any characters, _ is one character. IN checks a value against a list and replaces several ORs.
Save your progress
Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.
Start free Log in