RIGHT functions in SQL

The RIGHT() function in SQL is used to extract a specified number of characters from the right side of a string.

SQL Syntax

RIGHT(string, number_of_characters)

Example: Let's we have a table Employees.

Table: Employees

IDName
1Ashish
2Priya
3Rahul
4Sneha

Now we want to extract the last 3 characters from each employee's name.

SQL

SELECT RIGHT(name, 3) AS ShortName
FROM employees;  

If the name is "Ashish", the result will be "ish".

The result of the above query is shown below:

IDNameShortName
1Ashishish
2Priyaiya
3Rahulhul
4Snehaeha