MySQL REVERSE Function | Reverse String

Reverse Function reverses a string and returns the result. It is an inbuilt Function which works from MySQL 4.0 onwards. In this article, we will discuss the MySQL Reverse Function. Also, we will discuss a few examples of using it.


REVERSE (string)


The Reverse expects only one parameter. You need to pass the string you want to reverse in the parameters.

Return Value

The Reverse Function returns a string which is the reverse of the original input string.

MySQL Reverse Function Diagram


Let’s discuss a few examples of using MySQL Reverse.

Example 1: Basic Usage

mysql> SELECT REVERSE('Concatly');
| REVERSE('Concatly') |
| yltacnoC            |

You can reverse a string in MySQL by passing it in the reverse function as above. The function returns the reverse of the original string.

Example 2: SELECT Query

You can reverse a column’s value from a table using the Reverse Function as follows:

mysql> select user_name, REVERSE(user_name) as reverseUser from users;
| user_name     | reverseUser   |
| Vishesh Ahuja | ajuhA hsehsiV |
| Vishesh       | hsehsiV       |
| Rishabh       | hbahsiR       |
| Rishabh       | hbahsiR       |
| Example       | elpmaxE       |
| Chin          | nihC          |

Example 3: UPDATE Query

Also, you can use the function in an update query to update the existing columns in a table.

mysql> UPDATE users SET user_name = REVERSE(user_name);
Query OK, 6 rows affected (0.05 sec)
Rows matched: 6  Changed: 6  Warnings: 0

mysql> SELECT user_name from users;
| user_name     |
| ajuhA hsehsiV |
| hsehsiV       |
| hbahsiR       |
| hbahsiR       |
| elpmaxE       |
| nihC          |


In this article, we discussed the MySQL Reverse Function. You can learn more about it on the Official MySQL Documentation. Also, you can learn about more MySQL String Functions on Concatly.

Spread the Knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *