Skip to content
SQLSimplified
string

RIGHT()

Returns the last N characters from the right of a string.

Description

RIGHT returns the last n characters of a string, counting from the end. It's the mirror of LEFT and handy for suffixes like file extensions or the last digits of an identifier.

Syntax

RIGHT(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...

RIGHT vs SUBSTRING

RIGHT(s, n) is equivalent to SUBSTRING(s FROM LENGTH(s) - n + 1). Use RIGHT for a clean suffix.

Common Mistakes

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

See also: LEFT, SUBSTRING, LENGTH.

Search

Search lessons, functions, examples, and practice problems