Challenge - 5 Problems
Substring Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this SUBSTRING query?
Consider the following query on a table products with a column
product_code containing the value 'ABCD1234'. What will this query return?SELECT SUBSTRING(product_code, 2, 3) AS result FROM products WHERE product_code = 'ABCD1234';MySQL
SELECT SUBSTRING(product_code, 2, 3) AS result FROM products WHERE product_code = 'ABCD1234';
Attempts:
2 left
💡 Hint
Remember SUBSTRING starts at the given position and extracts the specified length.
✗ Incorrect
SUBSTRING(product_code, 2, 3) starts at position 2 (B) and extracts 3 characters: 'BCD'.
❓ query_result
intermediate2:00remaining
What does LEFT() return here?
Given a table users with a column
username containing 'charlie123', what is the result of this query?SELECT LEFT(username, 7) AS short_name FROM users WHERE username = 'charlie123';MySQL
SELECT LEFT(username, 7) AS short_name FROM users WHERE username = 'charlie123';
Attempts:
2 left
💡 Hint
LEFT() returns the first N characters from the string.
✗ Incorrect
LEFT(username, 7) returns the first 7 characters: 'charlie'.
📝 Syntax
advanced2:00remaining
Which query correctly extracts the last 4 characters using RIGHT()?
You want to get the last 4 characters from the column
serial in table devices. Which query is correct?Attempts:
2 left
💡 Hint
RIGHT() needs a positive integer length as second argument.
✗ Incorrect
RIGHT(serial, 4) extracts the last 4 characters. Negative or missing length causes errors or empty results.
❓ query_result
advanced2:00remaining
What is the output of this nested SUBSTRING and LEFT query?
Given a table files with a column
filename containing 'report_final_2023.pdf', what does this query return?SELECT LEFT(SUBSTRING(filename, 8), 5) AS part FROM files WHERE filename = 'report_final_2023.pdf';MySQL
SELECT LEFT(SUBSTRING(filename, 8), 5) AS part FROM files WHERE filename = 'report_final_2023.pdf';
Attempts:
2 left
💡 Hint
SUBSTRING starts at position 8, then LEFT takes first 5 characters of that substring.
✗ Incorrect
SUBSTRING(filename, 8) starts at 'f' in 'final_2023.pdf'. LEFT(..., 5) takes 'final'.
🧠 Conceptual
expert3:00remaining
Why might SUBSTRING() and LEFT()/RIGHT() produce different results on multibyte characters?
Consider a table texts with a column
content containing multibyte UTF-8 characters like emojis. Why can SUBSTRING() and LEFT()/RIGHT() behave differently when extracting parts of such strings?Attempts:
2 left
💡 Hint
Think about how string length is measured in bytes vs characters.
✗ Incorrect
SUBSTRING() counts characters properly in multibyte encodings, but LEFT()/RIGHT() count bytes, which can split characters incorrectly.