Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

LEFT

Example

Retrieve the first three characters from a string.

SELECT LEFT(“SQL Tutorial”, 3) AS 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(string, number_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, 5) AS ExtractString
FROM Customers;