MySQL RIGHT Function

MySQL Right is one of the String Function, which returns the rightmost characters of the user-specified expression (or column value). This function 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 example.

MySQL Right Syntax

The basic syntax of Right in MySQL is as shown below:

SELECT RIGHT (String_Expression, value)
FROM Source

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

MySQL Right Function Example 1

MySQL Right Example 1

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

-- MySQL String Right Example
SELECT RIGHT('Learn MySQL Server', 12) AS `Rightmost Characters`;

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

MySQL Right Example 2

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

-- MySQL String Right Example
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