Retrieve the first three characters from a string.
| SELECT LEFT(“SQL Tutorial”, 3) AS ExtractString; |
The LEFT() function retrieves a specified number of characters from the beginning of a string.
Tip: Consider exploring the RIGHT() function as well.
| LEFT(string, number_of_chars) |
|
Parameter |
Description |
|
string |
Necessary: The string from which extraction is required. |
|
number_of_chars |
Mandatory: The number of characters to extract. If this value exceeds the character count in the string, the function will return the entire string. |
| Works in: | From MySQL 4.0 |
Retrieve a substring of 5 characters from the text in the “CustomerName” column, starting from the left side.
| SELECT LEFT(CustomerName, 5) AS ExtractString FROM Customers; |