Solving tips
- Use LIKE with the % wildcard to match a substring at the start or end of a value.
- Anchor the pattern carefully: '%@gmail.com' matches the domain exactly, while '%gmail%' would over-match.
- % matches any run of characters and _ matches exactly one character.
You are given a customers table and need to identify everyone using a Gmail address for a targeted email campaign.
Schema
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT,
city TEXT
);
Sample data:
| id | name | city | |
|---|---|---|---|
| 1 | Alice Smith | alice@gmail.com | Boston |
| 2 | Bob Jones | bob@yahoo.com | Denver |
| 3 | Carol White | carol@gmail.com | Austin |
| 4 | Dan Brown | dan@company.org | Boston |
| 5 | Erin Black | erin.g@gmail.com | Seattle |
| 6 | Frank Green | frank@gmailx.com | Miami |
Task
Return the id, name, and email of every customer whose email ends with the domain @gmail.com. Order the rows by id in ascending order.
Expected output
| id | name | |
|---|---|---|
| 1 | Alice Smith | alice@gmail.com |
| 3 | Carol White | carol@gmail.com |
| 5 | Erin Black | erin.g@gmail.com |