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 | winston@leetcode.com |
| 2 | Jonathan | jonathanisgreat |
| 3 | Annabelle | bella-@leetcode.com |
| 4 | Sally | sally.come@leetcode.com |
| 5 | Marwan | quarz#2020@leetcode.com |
| 6 | David | david69@gmail.com |
| 7 | Shapiro | .shapo@leetcode.com |
Output:
| user_id | name | |
|---|---|---|
| 1 | Winston | winston@leetcode.com |
| 3 | Annabelle | bella-@leetcode.com |
| 4 | Sally | sally.come@leetcode.com |
| 5 | Marwan | quarz#2020@leetcode.com |
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');