Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

RIGHT

Example

Retrieve 4 characters from the right side of a string.

SELECT RIGHT(“SQL Tutorial is cool”, 4) AS ExtractString; 

Definition and Usage

The RIGHT() function retrieves a specified number of characters from a string, starting from the right.

Tip: Additionally, consider the LEFT() function for a similar operation.

Syntax

RIGHT(string, number_of_chars)

Parameter Values

Parameter

Description

string

Input required: The string from which extraction will be done.

number_of_chars

Input required: The number of characters to be extracted. If this parameter exceeds the number of characters in the string, the function will return the entire string.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Retrieve 5 characters from the right side of the text in the “CustomerName” column.

SELECT RIGHT(CustomerName, 5) AS ExtractString
FROM Customers;