Lessons › SQL › Deep Dive: Data Cleaning
SQL lesson
TRIM() / UPPER() / LOWER() for text cleanup
Text-cleanup functions strip extra spaces from the edges of a value or force every letter to the same case - upper or lower - so that entries meaning the same thing actually match when compared.
Try this lesson free →Example
Standardizing Retail Text with TRIM(), UPPER(), and LOWER()
SELECT product_id,
UPPER(TRIM(brand)) AS brand,
LOWER(TRIM(category)) AS category,
price
FROM products| product_id | brand | category | price |
|---|---|---|---|
| P1001 | NIKE | electronics | 89.99 |
| P1002 | ADIDAS | clothing | 45.5 |
| P1003 | ZARA | home | 120.0 |
| P1004 | UNIQLO | beauty | 29.99 |
| P1005 | SAMSUNG | electronics | 599.0 |
Step by step
- Run the query without UPPER so you can see what the unfiltered values look like.
SELECT product_id, TRIM, LOWER(TRIM(category)) AS category, price FROM products; - UPPER converts text to all uppercase letters.
SELECT product_id, UPPER(TRIM(brand)), LOWER(TRIM(category)) AS category, price FROM products; - AS gives the UPPER result a friendly column name so the output reads cleanly.
SELECT product_id, UPPER(TRIM(brand)) AS brand, LOWER(TRIM(category)) AS category, price FROM products;
Practice
1. Using customers, write a query to convert to lowercase the email column.
SELECT LOWER(email) FROM customers2. Using products, write a query to remove leading and trailing spaces from the brand column.
SELECT TRIM(brand) FROM products3. Using suppliers, write a query to convert to uppercase the country column.
SELECT UPPER(country) FROM suppliers4. Using employees, write a query to remove leading and trailing spaces from the role column.
SELECT TRIM(role) FROM employees5. Using reviews, write a query to remove leading and trailing spaces from the customer_id column.
SELECT TRIM(customer_id) FROM reviewsLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →