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
| Name | Description | Optional |
|---|---|---|
| string | The source text. | No |
| n | How 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.
LEFTjust returns the whole string; it doesn't error or pad. - Negative n. Behavior varies; prefer a non-negative count.
- Confusing with RIGHT.
RIGHTtakes from the end;LEFTfrom the start.
Related Functions
See also: RIGHT, SUBSTRING, LENGTH.