TRIM
removing leading and trailing spaces.
Overview
TRIM removes leading and trailing spaces by default and is useful for whitespace introduced by manual entry or imports. It does not remove spaces inside the string or permanently modify the source column unless the result is written back. MySQL can trim other specified characters, but verify that valid data will not be removed.
Basic syntax
SELECT TRIM(name) FROM users;
Examples
TRIM example
Remove surrounding spaces from users.name and compare the cleaned display value with the stored input.
Sample table
users| name |
|---|
| Tom |
| Jack |
| Lucy |
Run result
| TRIM(name) |
|---|
| Tom |
| Jack |
| Lucy |
Common issues
Check each function; with CONCAT, use COALESCE first when a fallback value is required.
Common MySQL syntax starts at 1; verify argument rules when moving to another database.
The default removes leading and trailing spaces only, not spaces within the value.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.