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, string LTRIM Function removes leading spaces from a given string. The basic syntax of MySQL LTRIM of a string is as shown below:


MySQL LTRIM Example 1

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

SELECT LTRIM('         Hi');

SELECT LTRIM('                   Hello');

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

LTRIM Example 2

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

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

This time, we used LTRIM on both the statements.

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