MySQL RIGHT Function

MySQL Right is one of the String functions, which returns the rightmost characters of the user-specified expression (or column value). This method uses its second argument to decide, How many characters it should return.

Let us see how to write MySQL String right function using Command Prompt and Workbench with an example, and the basic syntax of it is as shown below:

SELECT RIGHT(String_Expression, value)
FROM Source

For this demo, we are going to use the below-shown data

Employee Table 1

MySQL Right Function Example

The Right method returns the rightmost characters in a given string. The following string function query shows multiple ways to use this Right function.

SELECT RIGHT('Learn MySQL Server', 12) AS `Rightmost Characters`;

SELECT RIGHT('Tutorial Gateway', 7) AS `Rightmost Characters`;
RIGHT Example 1

MySQL also allows you to return the rightmost characters of the data inside the columns. In this example, we are going to find the rightmost characters of all the records present in the Department Name and Email column.

USE mysqltutorial;
SELECT  FirstName, LastName, 
		DepartmentName, 
        RIGHT(DepartmentName, 7) AS `Last 6 Characters in Department`,
        Email,
        RIGHT(Email, 9) AS `Last 9 Characters in Email`
FROM employe
ORDER BY FirstName, LastName;
MySQL RIGHT Example 2