How can I remove the leading and trailing spaces both at once from a string without using MySQL LTRIM() and RTRIM() functions?

MySQLMySQLi Database

Other than LTRIM() and RTRIM() functions, MySQL has TRIM() function to remove leading and trailing function both at once from a string. The use of TRIM() function can be understood from the following example of a test_trim table which has a column ‘Name’ containing the names with leading and trailing spaces.


mysql> Select Name, TRIM(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)
Published on 20-Feb-2018 09:01:38