Introduction
Data hygiene is an integral part of database management, and it often involves cleaning and formatting string data. One handy function provided by MySQL for this purpose is the TRIM() function.

In this article, we'll dive into the TRIM() function, its usage, and how it can help improve your data management process.
Understanding MySQL TRIM()
What is TRIM()?
The TRIM() function in MySQL is a string function that removes unwanted characters from both ends (leading and trailing) of a string. By default, it removes spaces, but it can be configured to remove any character.
Why Use TRIM()?
The TRIM() function is useful for:
Data Cleaning: Removing unnecessary spaces or characters from your data.
Data Formatting: Making sure your data is consistently formatted and easy to read.
The Syntax of TRIM()
The MySQL TRIM() function uses the following syntax:
TRIM([removal_string FROM] string);
Here removal_string is the string that should be removed from the string. If removal_string is not specified, the TRIM() function removes spaces.
Applying TRIM() in Real World Scenarios
Let's explore some examples to see how to use the TRIM() function.
Example 1: Basic Usage
SELECT TRIM(' Hello World ') AS TrimmedString;
This will output:
TrimmedString
Hello World

Example 2: Removing Specific Characters
We have a table 'Employees' with the following data:
Employee_ID Name
1 @@John Doe@@
2 @@Jane Doe@@
If we want to remove the '@@' from the names:

SELECT Employee_ID, TRIM('@' FROM Name) AS TrimmedName
FROM Employees;
This will result in:
Employee_ID TrimmedName
1 John Doe
2 Jane Doe
