Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

LEFT

Example

Retrieve the first three characters from a string.

SELECT LEFT(“SQL Tutorial”3AS ExtractString; 

Definition and Usage

The LEFT() function retrieves a specified number of characters from the beginning of a string.

Tip: Consider exploring the RIGHT() function as well.

Syntax

LEFT(stringnumber_of_chars)

Parameter Values

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.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Retrieve a substring of 5 characters from the text in the “CustomerName” column, starting from the left side.

SELECT LEFT(CustomerName, 5AS ExtractString
FROM Customers;