task TRIM / LOWER / SUBSTR / REPLACE · medium
Normalize contact import collisions
Find duplicate valid emails after lowercasing and trimming outer ASCII spaces, tabs, carriage returns and line feeds. Return normalized_email, source_rows and the smallest source id as first_id.
what to return
- Columns
normalized_emailsource_rowsfirst_idin this order- Rows
- 5 rows · in the order asked
- Watch for
- For this exercise only: exactly one @; a nonempty local part; domain has a dot that is neither its first nor last character; no consecutive domain dots; no ASCII space, tab, CR or LF anywhere after trimming.
- This is a deliberately limited import rule, not full email-standard validation. Keep plus aliases distinct; do not remove dots or plus suffixes.
- Return only groups with more than one valid source row, ordered by normalized_email.
- Skill
- Find normalized duplicate contacts while excluding malformed identifiers. Refresher: CAST, text types & NULL arithmetic →
expected result
Your query should return exactly these columns and values. Run it and compare.
expected result5 rows · in this order
| normalized_email | source_rows | first_id |
|---|---|---|
| ana+sale@harbor.test | 2 | 7 |
| ana@harbor.test | 2 | 1 |
| ben@harbor.test | 2 | 3 |
first 3 of 5 rows
data you can query
Sample rows from each table. Each column shows its type underneath; → marks a link to another table.
market_raw_import4 columns · 19 rows
| idinteger · key | raw_codetext | raw_emailtext | raw_amounttext |
|---|---|---|---|
| 1 | hm-0042-us | Ana@Harbor.test | 19.99 |
| 2 | HM-0007-GB | ana@harbor.test | 0.29 |
| 3 | HM-12x4-US | Ben@harbor.test | -12.50 |
| 4 | HM-12345-US | BEN@HARBOR.TEST | +12 |
| 5 | HM-123-US | a@@harbor.test | 12x |
showing 5 of 19 rows
solution.sql
Hints and the answer are always available. Using them counts the question as solved with help.