Beginner

230. TRIM Function

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

📘 Lesson 230 of 728 ⏱ 9 min 🎯 Beginner

The TRIM function removes leading and trailing whitespace from a text value. Some database systems also provide separate functions for removing characters from specific sides.

Unwanted spaces can cause incorrect comparisons, duplicate-looking values, failed joins, and data-quality problems.

Remove extra spaces from customer names before displaying or comparing them.

SQL
SELECT
    TRIM(CustomerName) AS CleanCustomerName
FROM Customers;

TRIM is widely used in data cleansing, customer data preparation, matching, validation, and ETL processes.

  • TRIM removes leading and trailing whitespace.
  • It helps clean text data.
  • It can improve matching and comparisons.
  • Different databases provide additional trimming functions.
  • TRIM is common in ETL and data cleansing.
What does TRIM do?

TRIM removes unwanted leading and trailing whitespace from a text value.

Why is TRIM useful in data analysis?

It helps clean inconsistent text values and can prevent matching and comparison problems caused by extra spaces.

Have you finished this lesson?

Introduction to SQL – All Lessons