MySQL LTRIM Function

MySQL LTRIM function is one of the String functions useful to remove empty spaces from the left side of a user given expression. Or say, MySQL LTRIM removes leading spaces from a given string and the basic syntax of it is as shown below:

LTRIM(String_Expression)

MySQL LTRIM Function Example

It removes the front or leading spaces from a given string and returns the remaining one. The following query shows multiple ways to use this LTRIM function.

SELECT LTRIM('         Hi');

SELECT LTRIM(' Hello');

SELECT LTRIM(' Hello ');
MySQL LTRIM Function 1

Here, we are joining two select statements using UNION. In the first statement, we used the LTRIM method. In the second select statement, we haven’t used this String method. It helps you understand the MySQL spaces.

SELECT LTRIM('     Hello') AS 'LTRIM Result'
UNION
SELECT ' World!';

This time, we used it on both the statements.

SELECT LTRIM('     Hello') AS 'LTRIM Result'
UNION
SELECT LTRIM(' World!');
MySQL LTRIM Function 2