LEFT() in MySQL — How It Works
What the MySQL LEFT() function does, with an example.
Published October 18, 2026
LEFT(str, n) returns the first n characters of a string.
How it works
It is shorthand for SUBSTRING(str, 1, n). If n is larger than the string, the whole string is returned.
Try it in MySQL
SELECT LEFT('abcdef', 3)
abc
SELECT LEFT('ab', 5)
ab
SELECT LEFT(name, 1) FROM users LIMIT 1
A
Practical examples
Example 1
SELECT LEFT('abcdef', 3);
-- abcExample 2
SELECT LEFT('ab', 5);
-- abExample 3
SELECT LEFT(name, 1) FROM users LIMIT 1;
-- AUse it in a real query
SELECT id, LEFT('abcdef', 3) AS result
FROM your_table
LIMIT 10;Common mistakes
- Using it where SUBSTRING_INDEX is needed.
- Negative n (returns empty).
- Truncating multi-byte characters by mistake (LEFT works on characters, not bytes).
Key takeaways
- LEFT() in one line: LEFT(str, n) returns the first n characters of a string.
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
How do I get the last n characters?
Use RIGHT(str, n).
Does LEFT() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.