String Pattern Extraction in Descriptions
Beginner Mode
Objective
Given a table named products with the columns product_id, name, description, and price, write an SQL query to retrieve the product_id, name, and the first email address found within the description for each product. Only include products that have an email address in their description. The resulting list should be ordered by product_id in ascending order.
Additional information
- An email address is defined by the pattern
[email protected]. - The extracted email should be the first occurrence found in the
description. - Products without an email address in the
descriptionshould not appear in the result. - Ensure the output columns are named exactly as
product_id,name, andemail_found.
Examples
Example 1:
Output:
Input:
| products | |||
|---|---|---|---|
| description | name | price | product_id |
| Contact support at [email protected] for warranty | Laptop | 999 | 1 |
| No email provided | Phone | 599 | 2 |
| For business inquiries: [email protected] | Tablet | 299 | 3 |
| Register at [email protected] for updates | Camera | 499 | 4 |
| email_found | name | product_id |
|---|---|---|
| [email protected] | Laptop | 1 |
| [email protected] | Tablet | 3 |
| [email protected] | Camera | 4 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Zscaler