In this guide, we will explain how to use the MySQL LEFT function with syntax and examples.
Description
The MySQL LEFT function allows you to extract a substring from a string, starting from the left-most character.
Syntax
The syntax for the LEFT function in MySQL is:
LEFT( string, number_of_characters )
Parameters or Arguments
string
The string that you wish to extract from.number_of_charactersThe number of characters that you wish to extract from a string starting from the left-most character.
Note
- If number_of_characters exceeds the length of string, the LEFT function will return string.
Applies To
The LEFT function can be used in the following versions of MySQL:
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some MySQL LEFT function examples and explore how to use the LEFT function in MySQL.
For example:
mysql> SELECT LEFT('Ad gl o b', 1); Result: 'A' mysql> SELECT LEFT('adglob.in', 4); Result: 'adgl' mysql> SELECT LEFT('adglob.in', 6); Result: 'adglob' mysql> SELECT LEFT('adglob.in', 100); Result: 'adglob.in'
Next Topic : Click Here
Pingback: MySQL: LCASE Function | Adglob Infosystem Pvt Ltd