CodeBlanks Logo Icon CodeBlanks

TRIM

Trim leading and trailing spaces.

TRIM

TRIM removes leading and trailing spaces. LTRIM cuts from the left, RTRIM from the right.

SELECT TRIM(name) AS temiz FROM customers;

This query removes leading and trailing spaces from names.

TRIM(name) AS temiz is selected from customers.

TRIM — details

Extra spaces from data entry break search. With TRIM you clean records and get more consistent matching.

Practice TRIM

Select name trimmed from customers.

Starter code

query.sql
-- trim spaces
SELECT
FROM customers

Sample solution

query.sql
SELECT TRIM(name) AS temiz
FROM customers

Expected output

temiz
Ayşe
Alex

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does TRIM remove?

  • All spaces
  • Leading and trailing spaces Correct answer
  • Only letters
  • Only numbers

Explanation: TRIM cuts leading and trailing spaces.

2 Trim right

Question
SELECT ____(name) FROM customers;
Answer
SELECT RTRIM(name) FROM customers;

Explanation: RTRIM removes spaces on the right (end) of the text.

3 TRIM: match the terms

Term Meaning
TRIM both sides
LTRIM left
RTRIM right
LENGTH length

All lessons in Beginner