You are given a Users table containing user information including their email addresses. Some of these emails are invalid and need to be filtered out.
Write a SQL query to find users who have valid emails.
A valid email must satisfy these conditions:
- The prefix name (before @) must start with a letter
- The prefix can contain letters (upper/lower case), digits, underscore '_', period '.', and/or dash '-'
- The domain must be exactly
@leetcode.com
Return the result in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Primary key, unique identifier for each user |
name
|
varchar | User's name |
mail
|
varchar | User's email address (may be invalid) |
Input & Output
| 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] |
| user_id | name | |
|---|---|---|
| 1 | Winston | [email protected] |
| 3 | Annabelle | [email protected] |
| 4 | Sally | [email protected] |
Valid emails: [email protected] (starts with letter, valid characters), [email protected] (starts with letter, dash allowed), [email protected] (starts with letter, period allowed). Invalid emails: jonathanisgreat (no @ domain), quarz#[email protected] (# not allowed), [email protected] (wrong domain).
| user_id | name | |
|---|---|---|
| 1 | Alice | [email protected] |
| 2 | Bob | [email protected] |
| 3 | Charlie | [email protected] |
| user_id | name | |
|---|---|---|
| 1 | Alice | [email protected] |
Only Alice's email is valid because it starts with a letter 'a'. Bob's email starts with digit '1' (invalid), and Charlie's email starts with underscore '_' (invalid). The prefix must start with a letter.
Constraints
-
1 ≤ user_id ≤ 1000 -
nameandmailare valid strings -
mailcontains valid ASCII characters