Beginner

55. TRIM Function

Learn how to remove unwanted spaces from the beginning and end of text values.

📘 Lesson 55 of 728 ⏱ 7 min 🎯 Beginner

The TRIM function removes leading and trailing spaces from a text value. It is commonly used during data cleaning when text values contain unnecessary spaces.

Extra spaces can cause matching and filtering problems. For example, 'Finance' and 'Finance ' may appear similar to a person but can behave differently in some comparisons and data-processing situations.

An employee department value may contain accidental spaces entered during data import. TRIM can remove unnecessary spaces before the value is analyzed.

SQL
SELECT
    TRIM(Department) AS CleanDepartment
FROM Employees;

TRIM is commonly used in data cleaning, imported datasets, customer records, employee records, and text standardization.

  • TRIM removes leading and trailing spaces.
  • TRIM is useful for cleaning text.
  • Extra spaces can cause data-quality issues.
  • TRIM can be used inside SELECT expressions.
  • TRIM behavior for internal spaces is different from leading or trailing spaces.
What does TRIM do in SQL?

TRIM removes unwanted leading and trailing spaces from text values.

Why is TRIM useful?

TRIM helps clean text values and reduce problems caused by accidental spaces.

Have you finished this lesson?

Introduction to SQL – All Lessons