TRIM removes leading and trailing whitespace from a string.
Imported or manually entered data can contain extra spaces that prevent otherwise valid JOIN matches.
Match department codes after removing unwanted spaces.
SELECT
e.EmployeeName,
d.DepartmentName
FROM Employees e
INNER JOIN Departments d
ON TRIM(e.DepartmentCode)
= TRIM(d.DepartmentCode);
Used in data imports, Excel-to-database integrations, migration projects, and data cleaning.
- TRIM removes surrounding whitespace.
- It can improve matching of dirty text data.
- Internal spaces are not normally removed.
- Function-based JOINs can affect performance.
- Cleaning data before storage is preferable when possible.
What does TRIM do?
TRIM removes leading and trailing whitespace from a string.
Why might TRIM be useful in a JOIN?
It can make values match when unwanted spaces were introduced during data entry or import.