Use MySQL REVERSE Function on Column Data with WHERE Clause



MySQL REVERSE() function can have the column name as an argument to invert its value. If we want to apply some condition/s then it can be used along with WHERE clause as follows:

Example

mysql> Select Name, REVERSE(Name) from Student;
+---------+---------------+
| Name    | REVERSE(Name) |
+---------+---------------+
| Aarav   | varaA         |
| Gaurav  | varuaG        |
| Gaurav  | varuaG        |
| Harshit | tihsraH       |
| Yashraj | jarhsaY       |
+---------+---------------+
5 rows in set (0.00 sec)

The above query inverts the values of ‘Name’ column from ‘Student’ table. Now, the query below will use the REPLACE() function with WHERE clause:

mysql> Select Name, REVERSE(Name) from Student WHERE Subject = 'History';
+-------+---------------+
| Name  | REVERSE(Name) |
+-------+---------------+
| Aarav | varaA         |
+-------+---------------+
1 row in set (0.00 sec)
Updated on: 2020-02-07T10:45:56+05:30

284 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements