MySQL Left is one of the String Function, which will return the left most 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 will show you, How to write MySQL String left Function using Command Prompt, and Workbench with example.
MySQL LEFT Syntax
The basic syntax of LEFT in MySQL is as shown below:
SELECT LEFT (String_Expression, value) FROM Source
For this, we are going to use the below shown data
MySQL Left Example 1
The string left function is used to return the left most characters in a given string. The following query will show 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 2
The string left function also allows you to return the left most characters of the data inside a table. In this example, we are going to find the left most characters of all the records present in Department Name, and Email column.
-- MySQL String Left Example USE mysqltutorial; SELECT FirstName, LastName, DepartmentName, LEFT(DepartmentName, 8) AS `First 8 Characters in Department`, Email, LEFT(Email, 4) AS `First 4 Characters in Email` FROM employe ORDER BY FirstName, LastName;
Thank You for Visiting Our Blog