MySQL RTRIM() function
RTRIM() function
MySQL RTRIM() removes the trailing spaces of a string.
This function is useful in -
- Trailing space removal: It allows us to remove trailing spaces from a string.
- Trailing character removal: RTRIM() can be used to remove a specified set of characters from the right side of a string.
- Data cleansing: To remove unwanted characters or spaces from strings, RTRIM() is often used.
Syntax:
RTRIM(str)
Argument:
Name | Description |
---|---|
str | A string whose trailing spaces are to be removed. |
Syntax Diagram:

MySQL Version: 8.0
Example: MySQL RTRIM() function
The following MySQL statement returns a string after removing all the trailing spaces of the argument string 'w3resource'.
Code:
SELECT RTRIM('w3resource ');
Output:
mysql> SELECT RTRIM('w3resource '); +----------------------+ | RTRIM('w3resource ') | +----------------------+ | w3resource | +----------------------+ 1 row in set (0.01 sec)
Example of MySQL RTRIM() function using table
The following MySQL statement returns the name of the authors with removing trailing spaces from the publisher table and home city of those authors. The WHERE condition is used to make sure that authors only those who belong to the USA are retrieved.
Code:
SELECT RTRIM(aut_name),home_city
FROM author
WHERE country='USA';
Sample table: author
Output:
mysql> SELECT RTRIM(aut_name),home_city -> FROM author -> WHERE country='USA'; +-----------------+-----------+ | RTRIM(aut_name) | home_city | +-----------------+-----------+ | Thomas Merton | New York | | Nikolai Dewey | Atlanta | | Joseph Milton | Houston | | Butler Andre | Florida | +-----------------+-----------+ 4 rows in set (0.00 sec)
Video Presentation:
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook