About this problem
You practise cleaning messy text without changing its meaning. contacts.full_name has doubled spaces inside names and stray spaces at the end, and you return each contact_id with a clean_name that has every run of whitespace collapsed to one space and the ends trimmed, sorted by contact_id. This is the step that has to happen before names can be matched, deduplicated or joined. The skill is choosing a function that handles any length of run, not just the ones you can see in the sample.
The tempting query is TRIM(REPLACE(full_name, ' ', ' ')). It works on a doubled space but not on longer runs: REPLACE scans once, so three spaces become two, and the sample has a name with three spaces between its parts. Nesting more REPLACE calls only handles runs up to a fixed length. The output looks tidy, and a leftover double space is hard to see in a results grid, so the miss is easy to overlook. The other trap is overreaching. The prompt says not to change case, so a row in capitals stays in capitals; adding LOWER() or INITCAP() makes the output wrong even though it looks tidier.
Read the lesson: String Functions (P12) →