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 | [email protected] | Boston |
| 2 | Bob Jones | [email protected] | Denver |
| 3 | Carol White | [email protected] | Austin |
| 4 | Dan Brown | [email protected] | Boston |
| 5 | Erin Black | [email protected] | Seattle |
| 6 | Frank Green | [email protected] | 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 | [email protected] |
| 3 | Carol White | [email protected] |
| 5 | Erin Black | [email protected] |