MySQL LEFT() Function
Example
Extract a substring from a string (starting from left):
SELECT LEFT("SQL Tutorial", 3) AS ExtractString;
Try it Yourself »
Definition and Usage
The LEFT() function extracts a substring from a string (starting from left).
Syntax
LEFT(string, number_of_chars)
Parameter Values
Parameter | Description |
---|---|
string | Required. The string to extract from |
number_of_chars | Required. The number of characters to extract |
Note
- If number_of_chars exceeds the number of characters in string, the LEFT() function will return string
Technical Details
Works in: | MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23 |
---|
More Examples
Example
Extract a substring from the text in a column (starting from left):
SELECT LEFT(CustomerName, 5) AS ExtractString
FROM Customers;
Try it Yourself »