Recall & Review
beginner
What does the TRIM function do in MySQL?
TRIM removes spaces or specified characters from both the beginning and the end of a string.
Click to reveal answer
beginner
How does LTRIM differ from TRIM?
LTRIM removes spaces only from the left (start) side of a string.
Click to reveal answer
beginner
What is the purpose of RTRIM in MySQL?
RTRIM removes spaces only from the right (end) side of a string.
Click to reveal answer
beginner
Write a MySQL query to remove spaces from both ends of the string ' hello '.
SELECT TRIM(' hello ') AS trimmed_string;
-- Result: 'hello'
Click to reveal answer
intermediate
Can TRIM remove characters other than spaces? How?
Yes, TRIM can remove other characters by specifying them. For example, TRIM(BOTH 'x' FROM 'xxhelloxx') removes 'x' from both ends.
Click to reveal answer
Which function removes spaces only from the start of a string in MySQL?
✗ Incorrect
LTRIM removes spaces from the left (start) side of the string.
What will SELECT TRIM(' data ') return?
✗ Incorrect
TRIM removes spaces from both ends, so the result is 'data'.
Which function removes spaces only from the right side of a string?
✗ Incorrect
RTRIM removes spaces from the right (end) side of the string.
How do you remove the character 'x' from both ends of 'xxhelloxx' in MySQL?
✗ Incorrect
TRIM with BOTH and character specified removes that character from both ends.
If you want to remove spaces only from the right side of a string, which function should you use?
✗ Incorrect
RTRIM removes spaces from the right side only.
Explain the difference between TRIM, LTRIM, and RTRIM functions in MySQL.
Think about which side of the string each function affects.
You got /3 concepts.
How can you use TRIM to remove a specific character other than space from a string?
TRIM is flexible and can remove characters you specify.
You got /3 concepts.