MySQL Right is one of the String Function, which will return the right most characters of the user specified expression (or column value). This function uses its second argument to decide, How many characters it should return. In this article we will show you, 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, we are going to use the below shown data
MySQL Right Example 1
The MySQL string Right function is used to return the right most characters in a given string. The following query will show 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 2
The string right function in MySQL also allows you to return the right most characters of the data inside the columns. In this example, we are going to find the right most characters of all the records present in 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;
Thank You for Visiting Our Blog