MySQL RTRIM() Function

The RTRIM() function in MySQL removes trailing spaces (spaces at the end) from a string. This is a very useful function for data cleaning and preparing strings for comparisons or other operations.



RTRIM(): Definition and Usage

Trailing whitespace (spaces at the end of a string) can sometimes cause unexpected behavior in string comparisons or other text-based operations. RTRIM() is a simple way to clean up strings by removing only those trailing spaces. Leading spaces (at the beginning of the string) or spaces within the string are unaffected.

Syntax

Syntax

RTRIM(string)
      

Parameter Values

Parameter Description
string The string from which you want to remove trailing spaces. This is required.

Example

Removing Trailing Spaces

This example removes trailing spaces from the string "SQL Tutorial ".

Syntax

SELECT RTRIM("SQL Tutorial    ") AS RightTrimmedString;
      
Output

SQL Tutorial