TRIM, UPPER, LOWER
Overview
TRIM, UPPER, LOWER β Clean and Format Text in SQL
These three functions help clean up messy text and make it consistent.
They are perfect for beginners because they fix common problems:
- Extra spaces in names
- Inconsistent capitalization
- Mixed case department names
- Data entered differently by different people
These functions make your results cleaner and easier to work with.
TRIM β Remove Extra Spaces
TRIM removes leading and trailing spaces from text.
TRIM(column)
Useful when data has:
- Spaces before the text
- Spaces after the text
- Both
Example idea:
' Math ' β 'Math'
UPPER β Convert Text to Uppercase
UPPER turns all letters into uppercase.
UPPER(column)
Example:
'math' β 'MATH'
LOWER β Convert Text to Lowercase
LOWER turns all letters into lowercase.
LOWER(column)
Example:
'SCIENCE' β 'science'
Examples Using The Education Database
Example 1: Clean up student names
SELECT TRIM(first_name) AS CleanFirstName,
TRIM(last_name) AS CleanLastName
FROM students;
Explanation (Beginner Friendly)
- Removes extra spaces at the start or end of names
- Useful when data was typed inconsistently
Example 2: Show all department names in uppercase
SELECT department,
UPPER(department) AS DeptUpper
FROM instructors;
Explanation
- Makes department names consistent
- Helps when comparing text values
Example 3: Show all course names in lowercase
SELECT course_name,
LOWER(course_name) AS CourseLower
FROM courses;
Explanation
- Converts everything to lowercase
- Useful for case insensitive matching
Example 4: Clean and standardize department names
SELECT TRIM(UPPER(department)) AS CleanDepartment
FROM instructors;
Explanation
- Removes extra spaces
- Converts to uppercase
- Produces clean, consistent department names
Why These Functions Matter
- Real data is often messy
- Users type things differently
- Extra spaces cause matching problems
- Upper/lowercase differences cause errors
These functions help beginners avoid common mistakes.
TRIM, UPPER, LOWER Summary
| Function | Purpose | Beginner Explanation |
|---|---|---|
TRIM |
Remove extra spaces | βClean up the text.β |
UPPER |
Convert to uppercase | βMake everything BIG letters.β |
LOWER |
Convert to lowercase | βMake everything small letters.β |
Practice Tasks (Your Turn!)
Task 1
Show student first and last names with spaces removed.
Task 2
Show instructor departments in uppercase.
Task 3
Show course names in lowercase.
Select a Task
Click a task from Practice Tasks to begin.
Click a task from Practice Tasks to begin.
Results will appear here…

