TRIM
- SQL course
- Beginner
- Lesson 39/115
- 4 min
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
-- trim spaces
SELECT
FROM customersSample solution
SELECT TRIM(name) AS temiz
FROM customersExpected 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
SELECT ____(name) FROM customers;
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 |