Right Function In Sql in SQL
? RIGHT() Function in SQL
The RIGHT() function returns the rightmost (last) n characters from a string.
? Syntax:
RIGHT(string, number_of_characters)string: The input string.number_of_characters: How many characters to extract from the right.
? Example 1: Basic Usage
SELECT RIGHT('Database', 4) AS result;? Output:
| result |
|---|
| base |
? Example 2: Extract last 2 digits of a number (as a string)
SELECT RIGHT('2025', 2) AS year_suffix;Output:
| year_suffix |
|---|
| 25 |
? Supported In:
MySQL
SQL Server
PostgreSQL (using
RIGHT()orsubstring())
? Related Functions:
| Function | Description |
|---|---|
LEFT() | Returns characters from the start of a string |
SUBSTRING() / SUBSTR() | Extracts any part of a string |
Want a comparison of LEFT(), RIGHT(), and SUBSTRING() with examples?