0
0
SQLquery~20 mins

TRIM, LTRIM, RTRIM in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Trim Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of TRIM removing spaces
What is the output of the following SQL query?

SELECT TRIM(' hello world ') AS trimmed_text;
SQL
SELECT TRIM('  hello world  ') AS trimmed_text;
A' hello world '
B' hello world'
C'hello world '
D'hello world'
Attempts:
2 left
💡 Hint
TRIM removes spaces from both the start and end of the string.
query_result
intermediate
2:00remaining
Output of LTRIM removing leading spaces
What is the output of this SQL query?

SELECT LTRIM(' data science ') AS left_trimmed;
SQL
SELECT LTRIM('  data science  ') AS left_trimmed;
A'data science '
B' data science'
C'data science'
D' data science '
Attempts:
2 left
💡 Hint
LTRIM removes spaces only from the start of the string.
query_result
advanced
2:00remaining
Output of RTRIM removing trailing spaces
What does this SQL query return?

SELECT RTRIM(' database ') AS right_trimmed;
SQL
SELECT RTRIM('  database  ') AS right_trimmed;
A'database '
B' database'
C'database'
D' database '
Attempts:
2 left
💡 Hint
RTRIM removes spaces only from the end of the string.
🧠 Conceptual
advanced
2:00remaining
Difference between TRIM, LTRIM, and RTRIM
Which statement correctly describes the difference between TRIM, LTRIM, and RTRIM functions in SQL?
ATRIM removes spaces from both ends; LTRIM removes spaces only from the left; RTRIM removes spaces only from the right.
BTRIM removes spaces only from the right; LTRIM removes spaces only from the left; RTRIM removes spaces from both ends.
CTRIM removes spaces only from the left; LTRIM removes spaces from both ends; RTRIM removes spaces only from the right.
DTRIM removes spaces only from the middle; LTRIM removes spaces only from the right; RTRIM removes spaces only from the left.
Attempts:
2 left
💡 Hint
Think about which side each function trims spaces from.
📝 Syntax
expert
2:00remaining
Identify the syntax error in TRIM usage
Which option will cause a syntax error when trying to remove leading and trailing spaces from the string ' example ' in standard SQL?
ASELECT TRIM(LEADING ' ' FROM ' example ') AS result;
BSELECT TRIM(' example ') AS result;
CSELECT TRIM(BOTH FROM ' example ') AS result;
DSELECT TRIM(BOTH ' ' FROM ' example ') AS result;
Attempts:
2 left
💡 Hint
Check the correct syntax for specifying which characters to trim in TRIM function.