Skip to main content

LEFT

Functions › Text › Take part of a string

Returns the first characters of a string.

Syntax​

LEFT( <string>, <n> )

Arguments​

ArgumentDescription
<string>The text to take from.
<n>How many characters to take. A negative number takes all but the last -<n> characters.

Returns​

Text. NULL when any argument is NULL. The whole string when <n> is at least its length.

Usage notes​

  • LEFT('invoice', -3) is invo.
  • A <n> that is not an integer is an error.
  • On large tables the engine runs it in the data store when <n> is a literal of 0 or more; otherwise it runs after the rows are read.

Examples​

SELECT p.sku, LEFT(p.sku, 2) AS family, COUNT(*) AS products
FROM Product p
GROUP BY p.sku, LEFT(p.sku, 2)
skufamilyproducts
AB-100AB1
AB-210AB1

See also​

RIGHT · SUBSTRING · LPAD · STARTS_WITH