Open In App

LEFT() Function in MySQL

Last Updated : 03 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The LEFT() function in MySQL is used to extract a specified number of characters from the left side of a given string. It uses its second argument to decide, how many characters it should return. 

Syntax:  

LEFT (str, len)


Parameter: This function accepts two parameters as mentioned above and described below : 

  • str: The given string from whose left side a number of characters are to be extracted. 
     
  • len: The number of characters to extract. If this parameter is larger than the number of characters in the string, this function will return the actual string. 
     

Returns: It returns a number of characters from a string (starting from left). 

Example 1: 
Applying LEFT() Function to a given string.  

SELECT LEFT("geeksforgeeks", 4) AS Left_Str;

Output: 

Left_Str
geek

Example 2: 
Applying Left() Function to a number.  

SELECT LEFT(12345678, 4) AS Left_Num;


Output: 

Left_Num
1234

Example 3: 
Applying LEFT() Function to a given string when len > characters in the string.  

SELECT LEFT("geeksforgeeks", 20) AS Left_Str;


Output : 

Left_Str
geeksforgeeks

Example 4: 
Applying LEFT() Function to a column in a table. 

Table : Student_Details 

Student_IdStudent_NameStudent_Email
1610110Aniket[email protected]
1610111Nitin[email protected]
1610112Sayantan[email protected]
1610113Sanjay[email protected]
SELECT Student_Name, LEFT(Student_Email, 9) AS Email_Name 
FROM Student_Details;


Output: 

Student_NameEmail_Name
Aniketanike1001
Nitinnitin5438
Sayantansayan6975
Sanjaysanjay506

Next Article
Article Tags :

Similar Reads