Easy MySQL solution
IntuitionThe problem requires extracting valid email addresses from a database. We need to ensure that the email format follows strict criteria:
It contains exa
# **Intuition**  
The problem requires extracting valid email addresses from a database. We need to ensure that the email format follows strict criteria:  
- It contains exactly **one `@` symbol**.  
- It **ends with `.com`**.  
- The **username (before `@`)** consists of only **alphanumeric characters and underscores**.  
- The **domain name (between `@` and `.com`)** consists of only **letters**.  

---

# **Approach**  
1. **Use `LIKE '%.com'` to filter `.com` emails first**  
   - This is a **faster operation** compared to `REGEXP`, as it avoids scanning unnecessary records.  

2. **Apply `REGEXP` for strict email validation**  
   - Ensure the **username** (`^[a-zA-Z0-9_]+`) contains only alphanumeric characters and underscores.  
   - Ensure the **domain name** (`[a-zA-Z]+`) consists of only **letters**.  
   - Escape the dot (`\\.com$`) to match the `.com` ending.  

---

# **Code**
```mysql
SELECT user_id, email
FROM Users
WHERE email LIKE '%.com' 
AND email REGEXP '^[a-zA-Z0-9_]+@[a-zA-Z]+\\.com$'
ORDER BY user_id;
```
['Database', 'MySQL']