Find Users With Valid E-Mails
Task: Write a solution to find the users who have valid emails. The domain must be @leetcode.com.
Table: Users
| Column Name | Type |
|---|---|
| user_id | INT |
| name | varchar(50) |
| varchar(50) |
Input: Users table:
| user_id | name | |
|---|---|---|
| 1 | Winston | [email protected] |
| 2 | Jonathan | jonathanisgreat |
| 3 | Annabelle | [email protected] |
| 4 | Sally | [email protected] |
| 5 | Marwan | quarz#[email protected] |
| 6 | David | [email protected] |
| 7 | Shapiro | [email protected] |
Output:
| user_id | name | |
|---|---|---|
| 1 | Winston | [email protected] |
| 3 | Annabelle | [email protected] |
| 4 | Sally | [email protected] |
| 5 | Marwan | quarz#[email protected] |
View Reference Solution & Explanation ▼
This solution uses pattern matching to filter string values to find the required output.
SELECT * FROM Users WHERE mail LIKE '%@leetcode.com' AND mail NOT LIKE '.%' AND (mail GLOB '[a-zA-Z]*@leetcode.com' OR mail GLOB '[a-zA-Z][a-zA-Z0-9_.-]*@leetcode.com');