Beginner

310. RIGHT Function

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

📘 Lesson 310 of 728 ⏱ 8 min 🎯 Beginner

The RIGHT function returns a specified number of characters from the end, or right side, of a string.

Business identifiers often contain meaningful suffixes. RIGHT can extract those values for classification and analysis.

Extract the last four characters of an account number.

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

RIGHT is useful for account masking, extracting suffixes, product codes, branch identifiers, and validation.

  • RIGHT extracts characters from the end.
  • The number of characters can be specified.
  • It is useful for identifiers.
  • It can support masking and validation.
  • Syntax may vary between databases.
What does RIGHT do?

RIGHT returns a specified number of characters from the end of a string.

Why is RIGHT useful with account numbers?

It can extract the final digits needed for identification or masked reporting without displaying the full account number.

Have you finished this lesson?

Introduction to SQL – All Lessons