Find and Trim Padded Emails
Return records whose non-NULL email changes when trimmed.
- String functions
- Filtering
- Sorting
Exercise brief
Understand the request
CRM data quality analyst A source feed contains email addresses padded on either side with spaces.
A source feed contains email addresses padded on either side with spaces. Return records whose non-NULL email changes when trimmed.
Return
- Return record_id, the raw email, and clean_email.
- Order by record_id ascending.
Constraints
- Compare the raw value with TRIM(email).
- Do not treat NULL or an already empty string as padded data.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
function_cases
record_idINTEGERfirst_nameTEXTlast_nameTEXTlabelTEXTemailTEXTbackup_emailTEXTphoneTEXTraw_unitsTEXTraw_quantityTEXTraw_statusTEXTactual_valueREALtarget_valueREALcompleted_unitsREALelapsed_hoursREAL
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
TRIM removes edge spaces, not spaces inside the address.
Hint 2
The cleanup predicate is raw_value <> TRIM(raw_value).
Hint 3
Keep the explicit IS NOT NULL condition so the intent is visible.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT record_id, email, TRIM(email) AS clean_email FROM function_cases WHERE email IS NOT NULL AND email <> TRIM(email) ORDER BY record_id;Why this works
Comparing a source value with its trimmed form isolates rows that actually need cleanup instead of rewriting every value blindly.
Success check
Only the three genuinely padded emails are returned and their internal characters remain unchanged.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| record_id | clean_email | |
|---|---|---|
| 101 | Alice.NG@Example.COM | Alice.NG@Example.COM |
| 105 | eve.li@example.com | eve.li@example.com |
| 108 | heidi@example.com | heidi@example.com |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
SELECT Statements
Select columns, filter rows, remove duplicates, and order query results.
CASE Statements & Conditional Logic
Build NULL-aware classifications, precedence-safe decisions, flags, scores, and guarded calculations with portable CASE expressions.
Date Operations & Time-Based Analytics
Practice date arithmetic, safe timestamp ranges, calendar bucketing, dense time series, rolling windows, growth, and cohort analysis.
Open the interactive workspace and practice across SQL topics.