LEFT returns the left part from a string, given a number of characters.
The number of characters must be a positive number, or an error will occur.
This example returns the first 8 characters from the input string.
SELECT LEFT('American Express', 8) AS 'Left'
| Left |
|---|
| American |
Syntax of the LEFT function.
LEFT(string, number)
string -- a string or column name.
number -- the number of characters to return.
| SUPPLIER |
|---|
| Id |
| CompanyName |
| ContactName |
| City |
| Country |
| Phone |
| Fax |
SELECT CompanyName, City,
UPPER(LEFT(Country, 2)) AS Country
FROM Supplier
| CompanyName | City | Country |
|---|---|---|
| Exotic Liquids | London | UK |
| New Orleans Cajun Delights | New Orleans | US |
| Grandma Kelly's Homestead | Ann Arbor | US |
| Tokyo Traders | Tokyo | JA |
| Cooperativa de Quesos 'Las Cabras' | Oviedo | SP |
| Mayumi's | Osaka | JA |
| Pavlova, Ltd. | Melbourne | AU |
![]() |
||
| CUSTOMER |
|---|
| Id |
| FirstName |
| LastName |
| City |
| Country |
| Phone |
SELECT FirstName + ' ' + LEFT(LastName,1) + '.' AS Name,
City, Country
FROM Customer
| Name | City | Country | ||
|---|---|---|---|---|
| Maria A. | Berlin | Germany | ||
| Ana T. | México D.F. | Mexico | ||
| Antonio M. | México D.F. | Mexico | ||
| Thomas H. | London | UK | ||
| Christina B. | Luleå | Sweden | ||
![]() |
||||