Beginner

203. RIGHT Function

Learn how to extract a specified number of characters from the end of a string.

📘 Lesson 203 of 728 ⏱ 8 min 🎯 Beginner

The RIGHT function returns a specified number of characters from the right side of a text value in database systems that support this function.

Suffix extraction is useful when analyzing codes, account identifiers, phone numbers, and other structured values.

Extract the last four digits of an account number.

SQL
SELECT
    RIGHT(AccountNumber, 4) AS LastFourDigits
FROM Accounts;

RIGHT is useful for extracting suffixes, reference numbers, identifiers, and formatted business codes.

  • RIGHT extracts characters from the end.
  • The second argument specifies the character count.
  • It is useful for suffix extraction.
  • Function availability varies by database.
  • It can be combined with other string functions.
What does RIGHT do?

RIGHT returns a specified number of characters from the end of a text value.

Give one use of RIGHT.

It can be used to extract the last few digits of an account number or identifier.

Have you finished this lesson?

Introduction to SQL – All Lessons