MySQL RTRIM Function

MySQL RTRIM function is one of the String methods which removes or deletes empty spaces from the right side of a user-given expression. Or say, this function removes trailing spaces from a given string.

Let me show you how to write a String RTRIM Function query to remove trailing empty spaces with an example. The basic syntax of RTRIM of a string is as shown below:

RTRIM(String_Expression)

MySQL RTRIM Function Example

The string RTRIM function removes the trailing spaces or right side empty spaces from a given string and returns the remaining sentence. The following query shows multiple ways to use this one.

SELECT RTRIM('MySQL             ');

SELECT RTRIM(' MySQL ');

SELECT RTRIM(' MySQL ') AS Result;
Example 1

You can also achieve the same using TRIM in MySQL. This String method example shows you how to use TRIM and RTRIM to remove the rightmost empty spaces.

SELECT RTRIM('         Tutorial Gateway         ') AS Result;

SELECT TRIM(TRAILING ' ' FROM ' Tutorial Gateway ') AS Result;

SELECT RTRIM('Tutorial Gateway ') AS Result;
RTRIM Example 2