LEFT
Returns the given number of characters from the beginning of a string.
MySQL 8.1
LEFT(str, number_of_characters)- str
- Source stringVARCHAR
- number_of_characters
- Number of characters to extractINT
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);First letter of a name
MySQL 8.1
SELECT member_name,
LEFT(member_name, 1) AS initial
FROM FamilyMembers;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.