Beginner

245. RIGHT Function

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

📘 Lesson 245 of 728 ⏱ 8 min 🎯 Beginner

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

RIGHT is useful for extracting suffixes, final digits, codes, and other information stored at the end of text values.

Extract the last four digits of an account reference.

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

RIGHT is commonly used for account numbers, reference codes, year extraction, and identifier processing.

  • RIGHT extracts characters from the end.
  • The number of characters is specified.
  • It is useful for suffixes.
  • It can extract final digits from identifiers.
  • Function support varies by database.
What does RIGHT do?

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

Where can RIGHT be useful?

It can be used to extract suffixes, final digits, and other information located at the end of a string.

Have you finished this lesson?

Introduction to SQL – All Lessons