Using TRIM, LTRIM, and RTRIM Functions in MySQL
📖 Scenario: You work in a customer service team. You have a database table that stores customer names, but some names have extra spaces at the start or end. These spaces can cause problems when searching or sorting names.
🎯 Goal: You will create a table with customer names that include extra spaces. Then, you will use MySQL's TRIM, LTRIM, and RTRIM functions to clean these names by removing unwanted spaces.
📋 What You'll Learn
Create a table called
customers with a column name containing names with extra spacesAdd a variable to hold a sample name with spaces
Write a query using
LTRIM to remove spaces from the start of the nameWrite a query using
RTRIM to remove spaces from the end of the nameWrite a query using
TRIM to remove spaces from both ends of the name💡 Why This Matters
🌍 Real World
Cleaning user input or imported data that may have unwanted spaces is common in databases to ensure accurate searching and reporting.
💼 Career
Database administrators and developers often need to clean and normalize text data to maintain data quality and improve query results.
Progress0 / 4 steps