Basic SQL Functions SQL Topic exerciseEasyVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

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_idINTEGER
  • first_nameTEXT
  • last_nameTEXT
  • labelTEXT
  • emailTEXT
  • backup_emailTEXT
  • phoneTEXT
  • raw_unitsTEXT
  • raw_quantityTEXT
  • raw_statusTEXT
  • actual_valueREAL
  • target_valueREAL
  • completed_unitsREAL
  • elapsed_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_idemailclean_email
101 Alice.NG@Example.COM Alice.NG@Example.COM
105 eve.li@example.comeve.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

SQL Practice Online

Open the interactive workspace and practice across SQL topics.