LTRIM( )

This MySQL function returns the given string with any leading spaces removed.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

LTRIM(string)

Explanation

This function returns the given string with any leading spaces removed. When using with an SQL statement such as UPDATE, rows that do not contain leading spaces will not be changed. This function is multi-byte safe. To trim trailing spaces, use RTRIM(); use TRIM() to trim both leading and trailing spaces.

Examples

UPDATE students
SET name_last = LTRIM(name_last);

In this example, the last names of several students have been entered inadvertently with a space in front of the names. This SQL statement removes any leading spaces from each name retrieved that contains leading spaces and then writes the trimmed text over the existing data.