Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
LIKE filtering | Filtering
SQL Basics
course content

Зміст курсу

SQL Basics

SQL Basics

1. Selecting
2. Filtering
3. Aggregating
4. Sorting
5. Grouping
6. Practicing

bookLIKE 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.

123
SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
copy

Please note, that you need to place your pattern within single quotes!

Завдання
test

Swipe to show code editor

From the audi_cars table extract all the A-series cars (model starts with the letter A).

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 6
toggle bottom row

bookLIKE 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.

123
SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
copy

Please note, that you need to place your pattern within single quotes!

Завдання
test

Swipe to show code editor

From the audi_cars table extract all the A-series cars (model starts with the letter A).

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 6
toggle bottom row

bookLIKE 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.

123
SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
copy

Please note, that you need to place your pattern within single quotes!

Завдання
test

Swipe to show code editor

From the audi_cars table extract all the A-series cars (model starts with the letter A).

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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.

123
SELECT * FROM visitors WHERE email LIKE '%@gmail.com'
copy

Please note, that you need to place your pattern within single quotes!

Завдання
test

Swipe to show code editor

From the audi_cars table extract all the A-series cars (model starts with the letter A).

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 6
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt