
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to remove trailing spaces
To remove trailing space, use RTRIM() in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> FirstName varchar(50) -> ); Query OK, 0 rows affected (1.38 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John '); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Chris '); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(' David '); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------------+ | FirstName | +-------------------+ | John | | Chris | | David | | Mike | +-------------------+ 4 rows in set (0.00 sec)
Here is the MySQL query to remove trailing spaces using RTRIM() −
mysql> select rtrim(FirstName) as FirstName from DemoTable;
This will produce the following output −
+-------------+ | FirstName | +-------------+ | John | | Chris | | David | | Mike | +-------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL update query to remove spaces?
- MySQL update query to remove spaces between letters?
- Trim a string in Java to remove leading and trailing spaces
- Trim (Remove leading and trailing spaces) a string in C#
- Remove Trailing Zero in MySQL?
- How to remove white spaces (leading and trailing) from string value in MongoDB?
- How to Add Trailing Spaces to Text in Excel?
- How to remove leading and trailing whitespace in a MySQL field?
- MySQL query to remove first digit?
- How can I remove the leading and trailing spaces both at once from a string by using MySQL LTRIM() and RTRIM() functions?
- How can I remove the leading and trailing spaces both at once from a string without using MySQL LTRIM() and RTRIM() functions?
- How to remove leading and trailing whitespace from a MySQL field value?
- Remove trailing numbers surrounded by parenthesis from a MySQL column
- How to remove double or more spaces from a string in MySQL?
- Remove trailing zeros in decimal value with changing length in MySQL?

Advertisements