MySQL returns a specified number of characters of a string with the help of LEFT() and RIGHT() functions.
MySQL LEFT() function will return the specified number of characters from the left of the string.
Syntax
LEFT(str, length)
Here str is the string from which a number of characters would be returned and the length is an integer value which specifies how many characters to be returned.
Example
mysql> Select LEFT('My Name is Ram', 7); +---------------------------+ | LEFT('My Name is Ram', 7) | +---------------------------+ | My Name | +---------------------------+ 1 row in set (0.00 sec)
MySQL RIGHT() function will return the specified number of characters from the right of the string.
Syntax
RIGHT(str, length)
Here str is the string from which a number of characters would be returned and the length is an integer value which specifies how many characters to be returned.
Example
mysql> Select RIGHT('My name is Ram',6); +---------------------------+ | RIGHT('My name is Ram',6) | +---------------------------+ | is Ram | +---------------------------+ 1 row in set (0.00 sec)