The LEFT function returns a specified number of characters from the beginning of a string. It is commonly used to extract prefixes and codes.
Many business identifiers contain meaningful information at the beginning of a value. LEFT allows analysts to extract that information for filtering, grouping, and analysis.
A customer code such as 'IND10025' may contain a three-character country prefix. LEFT can extract 'IND'.
SELECT
CustomerCode,
LEFT(CustomerCode, 3) AS CountryCode
FROM Customers;
LEFT is useful for extracting region codes, country codes, product prefixes, account prefixes, and other structured text.
- LEFT extracts characters from the beginning of a string.
- The number of characters can be specified.
- It is useful for extracting prefixes.
- It can help categorize structured text.
- Function syntax can vary between database systems.
What does LEFT do in SQL?
LEFT returns a specified number of characters from the beginning of a string.
Where is LEFT commonly used?
It is commonly used to extract prefixes, codes, and other information stored at the beginning of a text value.