Function Reference

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;
result
[Hello ]

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;
promo_codelengthlength_after_ltrimorders
<NULL><NULL><NULL>159
[]0078
[ ]3042
[VIP30]5554
[SUMMER20]8865
[WELCOME10]9958

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.

See also