MySQL LEFT Function

MySQL Left function is one of the String Functions, which returns the leftmost characters of the user-specified expression. This left function uses its second argument to decide, How many characters it has to return.

In this article, we show how to write MySQL String left Function using Command Prompt, and Workbench with example.


The basic syntax of LEFT in MySQL is as shown below:

SELECT LEFT (String_Expression, value)
FROM Source

For this string left function in MySQL demonstration, we are going to use the below shown data

MySQL Left Function Example 1

MySQL Left Example 1

The left string function returns the leftmost characters in a given string. The following string function query shows multiple ways to use this Left function.

-- MySQL String Left Example
SELECT LEFT('Learn MySQL Server', 11) AS `Leftmost Characters`;

SELECT LEFT('Tutorial Gateway', 8) AS `Leftmost Characters`;
MySQL LEFT Example 1

MySQL Left Example 2

The string left in MySQL also allows you to return the leftmost characters of the data inside a table. In this MySQL example, we are going to find the leftmost characters of all the records present in the Department Name and Email column.

-- MySQL String Left Example
USE mysqltutorial;
SELECT  FirstName, LastName, 
        LEFT(DepartmentName, 8) AS `First 8 Characters in Department`,
        LEFT(Email, 4) AS `First 4 Characters in Email`
FROM employe
ORDER BY FirstName, LastName;
MySQL LEFT Example 2