Function Reference

LEFT

Returns the given number of characters from the beginning of a string.

MySQL 8.1
LEFT(str, number_of_characters)
str
Source string
VARCHAR
number_of_characters
Number of characters to extract
INT

Return value

The first number_of_characters characters; the whole string if it is shorter; an empty string if number_of_characters is less than 1

Examples

First three characters

MySQL 8.1
SELECT LEFT('sql-academy', 3);
LEFT('sql-academy', 3)
sql

First letter of a name

MySQL 8.1
SELECT member_name,
	LEFT(member_name, 1) AS initial
FROM FamilyMembers;
member_nameinitial
Headley QuinceyH
Flavia QuinceyF
Andie QuinceyA
Lela QuinceyL
Annie QuinceyA
Ernest ForrestE
Constance ForrestC
Wednesday AddamsW

Details

Characters are counted, not bytes: LEFT('привет', 2) returns пр. A negative number gives an empty string, while in PostgreSQL it gives the whole string without the last characters: LEFT('abcdef', -2) returns abcd there.

See also

Where to learn