lesson 06 Filtering & sorting · beginner
Lists & text patterns
Match lists of values and patterns in text.
the idea
IN matches any member of a list. LIKE matches text patterns: % means any number of characters and _ means one character. SQLite LIKE is case-insensitive for ASCII by default.
tables in this lesson
The challenges use this data. Each column shows its type underneath; → marks a link to another table.
customers4 columns · 8 rows
| idinteger · key | nametext | citytext | joined_attext |
|---|---|---|---|
| 1 | Alice | Chicago | 2024-01-10 |
| 2 | Ben | Austin | 2024-02-12 |
| 3 | Cara | Seattle | 2024-03-05 |
| 4 | Dev | Chicago | 2024-04-20 |
| 5 | Elena | NULL | 2024-05-01 |
showing 5 of 8 rows
example
The idea in one query. Press Run to see what it returns; running examples never affects your progress.
SELECT name FROM customers WHERE name LIKE 'A%';
Watch for: An equality comparison with A% looks for a literal percent sign.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Match the start of a name. In LIKE, % stands for the rest of the name. It is not a character stored in the table.
step-1.sqlSELECT name FROM customers;
Run the reference. IN matches any member of a list. LIKE matches text patterns: % means any number of characters and _ means one character. SQLite LIKE is case-insensitive for ASCII by default.
step-2.sqlSELECT name FROM customers WHERE name LIKE 'A%';