- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I remove the leading and trailing spaces both at once from a string by using MySQL LTRIM() and RTRIM() functions?
For removing both leading and trailing spaces at once from a string by using LTRIM() and RTRIM() functions, we must have to use one function as an argument for other function. In other words, we must have to pass either LTRIM() function as an argument of RTIM() function or vice versa. It can be understood from the following example −
Example
Suppose we have a table ‘test_trim’ having a column ‘Name’ containing the values with leading and trailing spaces both −
mysql> Select * from test_trim; +---------------+ | Name | +---------------+ | Gaurav | | Rahul | | Aarav | +---------------+ 3 rows in set (0.00 sec)
Now the following query will remove the leading and trailing spaces at once from the names by using LTRIM() and RTRIM() functions −
mysql> Select Name, LTRIM(RTRIM(Name))AS 'Name Without Spaces' from test_trim; +---------------+---------------------+ | Name | Name Without Spaces | +---------------+---------------------+ | Gaurav | Gaurav | | Rahul | Rahul | | Aarav | Aarav | +---------------+---------------------+ 3 rows in set (0.00 sec) mysql> Select Name, RTRIM(LTRIM(Name))AS 'Name Without Spaces' from test_trim; +---------------+---------------------+ | Name | Name Without Spaces | +---------------+---------------------+ | Gaurav | Gaurav | | Rahul | Rahul | | Aarav | Aarav | +---------------+---------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How can I remove the leading and trailing spaces both at once from a string without using MySQL LTRIM() and RTRIM() functions?
- Trim (Remove leading and trailing spaces) a string in C#
- How to remove white spaces (leading and trailing) from string value in MongoDB?
- How MySQL LTRIM() and RTRIM()functions can be used with WHERE clause?
- Trim a string in Java to remove leading and trailing spaces
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- How to remove leading and trailing whitespace from a MySQL field value?
- How can we eradicate leading and trailing space characters from a string in MySQL?
- Java Program to remove leading and trailing whitespace from a string
- Java Program to remove the leading and trailing quotes from a string
- How to remove leading and trailing whitespace in a MySQL field?
- MySQL query to remove trailing spaces
- Python Pandas – Remove leading and trailing whitespace from more than one column
- Remove trailing numbers surrounded by parenthesis from a MySQL column
- How to remove double or more spaces from a string in MySQL?

Advertisements