22. 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.
Essential
SQL 0/33
Spark 0/20
Snowflake 0/22
Python 0/24
Need more practice in this area? Explore more questions →
Zscaler
Revolut
Accenture
Adobe
Google
LinkedIn
Samsung
Datadog
Wix
Dropbox
Meta
OpenAI
Hulu
Uber
X
DoorDash
Anthropic
Amazon
ActivisionBlizzard
Vercel
Crypto.Com
DeutscheBank
Apple
GoDaddy
GitLab
BMW
PayPal
Snowflake
AMD
Twilio
Atlassian
JPMorgan
NVIDIA
IBM
Databricks
Coinbase
Cisco
Robinhood
Twitter
Microsoft
Palantir
Netflix
VMware
Cloudflare
Stripe
Lyft
Salesforce
GitHub
Bloomberg
Airbnb
Walmart
SAP
HashiCorp
Instacart
Mastercard
Intel
Visa
Tesla