Brightlane's contact deduplication job normalizes customer names by converting to lowercase and removing leading and trailing spaces before comparison.
Write a query to return the cleaned version of the name ' Owen Marshall '.
Output:
- A single row with one column,
normalized_name, containing the lowercased and trimmed string.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
TRIM(LOWER(' Owen Marshall ')) AS normalized_name The shape
The two functions compose in one expression: LOWER(...) runs first against the padded literal and produces ' owen marshall ', then TRIM(...) runs against that intermediate value and produces 'owen marshall'. Nesting from the inside out lets one SELECT expression carry both normalization steps the deduplication job needs.
Clause by clause
SELECT TRIM(LOWER(' Owen Marshall ')) AS normalized_nameruns the two transforms in order. The innerLOWERreturns the casing-normalized form of the input, padding included; the outerTRIMthen strips the leading and trailing spaces from that result. The aliasnormalized_namelabels the final cleaned value.- There is no
FROMbecause both functions operate on the literal embedded in theSELECT. Each function takes one input and returns one output, and the two outputs chain straight through.
Why this order and not LOWER(TRIM(...))
Both orderings produce the same result on this input, because lowercasing leaves spaces unchanged and trimming leaves casing unchanged. The two transforms commute here. They do not always: a transform that depends on the boundary character (a SUBSTRING keyed off the first non-space, for instance) would care about whether trimming happened first. When transforms genuinely commute, either nesting reads correctly; the habit of running case normalization inside and trimming outside is a convention worth keeping for consistency across the pipeline.
You practiced composing TRIM(LOWER(...)) — chain two single-row transforms so the inner result feeds the outer call in one expression.