MySQL RTRIM Function

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

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



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

SELECT RTRIM('MySQL             ');

SELECT RTRIM('              MySQL             ');

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

You can also achieve the same using the TRIM function in the MySQL. This String Function 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;
MySQL RTRIM Function 2