MySQL REVERSE Function

MySQL Reverse is one of the String Function, which is useful to reverse the user-specified expression (or column value). In this article, we reveal to you, How to write MySQL String reverse using Command Prompt and Workbench with example.

MySQL Reverse Syntax

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

SELECT REVERSE (String_Expression)
FROM Source

For this string reverse function demonstration, we are going to use the below shown data

MySQL Reverse Function Example 1

MySQL Reverse Example 1

The MySQL string Reverse function reverses the given string and returns the output. The following query shows multiple ways to use this Reverse function.

-- MySQL String Reverse Example
SELECT REVERSE('Learn MySQL Server') AS `Reversed String`;

SELECT REVERSE('Tutorial Gateway') AS `Reversed String`;
SQL REVERSE Example 1

MySQL Reverse Example 2

The reverse string in MySQL also allows you to reverse the data inside the table columns. In this string function example, we are going to reverse the length string data present in the Department Name and Email column.

-- MySQL String Reverse Example
USE mysqltutorial;
SELECT  FirstName, LastName, 
		DepartmentName, 
        REVERSE(DepartmentName) AS `Department in Reverse`,
        Email,
        REVERSE(Email) AS `Email in Reverse`
FROM employe
ORDER BY FirstName, LastName;

SQL REVERSE Example 2