REVERSE(str)
is a MySQL string function that returns the string str
with its characters in reverse order.
- It works on any string or text column.
- Useful for text manipulation, puzzles, or formatting.
Syntax
REVERSE(str)
Example Queries and Results
1. Reverse a simple string
SELECT REVERSE('hello');
- Result: 'olleh'
2. Reverse a phrase
SELECT REVERSE('MySQL is fun!');
- Result: '!nuf si LQSyM'
3. Reverse a column value (e.g., cat names)
SELECT name, REVERSE(name) AS reversed_name FROM cats;
-- Example result:
-- | name | reversed_name |
-- |---------|---------------|
-- | Whiskers| srekhsihW |
-- | Luna | anuL |
4. Reverse book titles
SELECT title, REVERSE(title) AS reversed_title FROM books;
-- Example result:
-- | title | reversed_title |
-- |---------------|--------------------|
-- | The Namesake | ekasemaN ehT |