LTRIM
Removes spaces at the beginning of a string.
MySQL 8.1
LTRIM(str)Parameters
- strVARCHAR
- Source string
Return value
A string without leading spaces; tabs and line breaks are kept
Examples
Spaces removed on the left
MySQL 8.1
SELECT CONCAT('[', LTRIM(' Hello '), ']') AS result;Promo codes made of spaces only
MySQL 8.1
SELECT CONCAT('[', promo_code, ']') AS promo_code,
CHAR_LENGTH(promo_code) AS length,
CHAR_LENGTH(LTRIM(promo_code)) AS length_after_ltrim,
COUNT(*) AS orders
FROM orders
GROUP BY promo_code
ORDER BY length;Details
Only spaces are removed. To remove other characters, use TRIM(LEADING '0' FROM str). In PostgreSQL, LTRIM takes a second argument with the set of characters to remove, but MySQL has no such argument.