LIKE filtering
Sometimes you need to filter by some non-numeric column, but not by exact value, but some pattern.
One of the clearest examples is filtering emails so only emails hosted on google will be left (@gmail.com). In SQL it can be done by using LIKE
statement and pattern built by using some wildcards. The most common wildcards are:
%
- represents zero, one or more symbols_
- represents one, and only one symbol.
For example, pattern a%
will match everything starting with a (even single symbol a), pattern _B
will match only two-letters strings ending with B.
To solve the task above we can use pattern %@gmail.com
, as there is usually more than one symbol before @
symbol, but we don't know the exact number.
123SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
Please note, that you need to place your pattern within single quotes!
Swipe to start coding
From the audi_cars
table extract all the A-series cars (model starts with the letter A).
Løsning
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 2.63Awesome!
Completion rate improved to 2.63
LIKE filtering
Sometimes you need to filter by some non-numeric column, but not by exact value, but some pattern.
One of the clearest examples is filtering emails so only emails hosted on google will be left (@gmail.com). In SQL it can be done by using LIKE
statement and pattern built by using some wildcards. The most common wildcards are:
%
- represents zero, one or more symbols_
- represents one, and only one symbol.
For example, pattern a%
will match everything starting with a (even single symbol a), pattern _B
will match only two-letters strings ending with B.
To solve the task above we can use pattern %@gmail.com
, as there is usually more than one symbol before @
symbol, but we don't know the exact number.
123SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
Please note, that you need to place your pattern within single quotes!
Swipe to start coding
From the audi_cars
table extract all the A-series cars (model starts with the letter A).
Løsning
Tak for dine kommentarer!
single
Awesome!
Completion rate improved to 2.63
LIKE filtering
Stryg for at vise menuen
Sometimes you need to filter by some non-numeric column, but not by exact value, but some pattern.
One of the clearest examples is filtering emails so only emails hosted on google will be left (@gmail.com). In SQL it can be done by using LIKE
statement and pattern built by using some wildcards. The most common wildcards are:
%
- represents zero, one or more symbols_
- represents one, and only one symbol.
For example, pattern a%
will match everything starting with a (even single symbol a), pattern _B
will match only two-letters strings ending with B.
To solve the task above we can use pattern %@gmail.com
, as there is usually more than one symbol before @
symbol, but we don't know the exact number.
123SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
Please note, that you need to place your pattern within single quotes!
Swipe to start coding
From the audi_cars
table extract all the A-series cars (model starts with the letter A).
Løsning
Tak for dine kommentarer!