MySQL LTRIM() Function
The LTRIM()
function in MySQL removes leading spaces (spaces at the beginning) from a string. This is a very common and useful function for data cleaning and ensuring data consistency.
LTRIM(): Definition and Usage
Leading whitespace (spaces at the start of a string) can cause problems in string comparisons or other operations. LTRIM()
is a simple and efficient way to remove these leading spaces, leaving you with just the main string content. Note that spaces within or at the end of the string are not affected.
Syntax
Syntax
LTRIM(string)
Parameter Values
Parameter | Description |
---|---|
string |
The string from which leading spaces should be removed. This is required. |
Example
Removing Leading Spaces
This example demonstrates removing leading spaces from the string " SQL Tutorial".
Syntax
SELECT LTRIM(" SQL Tutorial") AS LeftTrimmedString;
Output
SQL Tutorial