Skip to content
SQLSimplified
string

LEFT()

Returns the first N characters from the left of a string.

Description

LEFT returns the first n characters of a string, counting from the left. It's a convenient shorthand for SUBSTRING(string FROM 1 FOR n) and is great for prefixes like area codes or initials.

Syntax

LEFT(string, n)

Parameters

NameDescriptionOptional
stringThe source text.No
nHow many characters to take.No

Return Type

Returns a VARCHAR.

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

LEFT vs SUBSTRING

LEFT(s, n) is equivalent to SUBSTRING(s FROM 1 FOR n). Use LEFT for readability when you want a prefix.

Common Mistakes

  • n larger than the string. LEFT just returns the whole string; it doesn't error or pad.
  • Negative n. Behavior varies; prefer a non-negative count.
  • Confusing with RIGHT. RIGHT takes from the end; LEFT from the start.

See also: RIGHT, SUBSTRING, LENGTH.

Search

Search lessons, functions, examples, and practice problems