runtime
06 / 88

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 · keynametextcitytextjoined_attext
1AliceChicago2024-01-10
2BenAustin2024-02-12
3CaraSeattle2024-03-05
4DevChicago2024-04-20
5ElenaNULL2024-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.

example.sql
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.

  1. 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.sql
    SELECT name
    FROM customers;
  2. 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.sql
    SELECT name
    FROM customers
    WHERE name LIKE 'A%';

challenge 1

Show name for customers whose name starts with A.

Return nameany row order

challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.