SQLPathLab
String Functions · Basic

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

Table:users
users
name
Tom
Jack
Lucy

Run result

result
TRIM(name)
Tom
Jack
Lucy

Common issues

What happens when a string function receives NULL?

Check each function; with CONCAT, use COALESCE first when a fallback value is required.

Where does SUBSTRING indexing begin?

Common MySQL syntax starts at 1; verify argument rules when moving to another database.

Does TRIM remove spaces inside a string?

The default removes leading and trailing spaces only, not spaces within the value.

Tags

CommonString

Was this explanation clear?