Challenge - 5 Problems
CONCAT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of CONCAT with NULL values
Consider the following SQL query:
What will be the output of this query?
SELECT CONCAT('Hello', NULL, 'World') AS result;What will be the output of this query?
SQL
SELECT CONCAT('Hello', NULL, 'World') AS result;
Attempts:
2 left
💡 Hint
Remember how CONCAT handles NULL values in SQL.
✗ Incorrect
In many SQL dialects like MySQL, CONCAT treats NULL as an empty string, so CONCAT('Hello', NULL, 'World') returns 'HelloWorld'.
❓ query_result
intermediate2:00remaining
Using CONCAT_WS with NULL values
What is the output of this SQL query?
SELECT CONCAT_WS('-', '2024', NULL, '06', '15') AS date_str;SQL
SELECT CONCAT_WS('-', '2024', NULL, '06', '15') AS date_str;
Attempts:
2 left
💡 Hint
CONCAT_WS skips NULL values when concatenating.
✗ Incorrect
CONCAT_WS skips NULL values and does not add extra separators for them. So the NULL is ignored and the output is '2024-06-15'.
📝 Syntax
advanced2:00remaining
Identify the syntax error in CONCAT usage
Which of the following SQL statements will cause a syntax error?
Attempts:
2 left
💡 Hint
Look for missing arguments or commas.
✗ Incorrect
Option B has two commas with no argument between them, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing string concatenation with CONCAT_WS
You want to concatenate first name, middle name, and last name with spaces between them. Middle name can be NULL. Which query produces the correct full name without extra spaces?
Attempts:
2 left
💡 Hint
CONCAT_WS skips NULL values and adds separators only between non-NULL values.
✗ Incorrect
CONCAT_WS with space separator skips NULL middle_name and avoids extra spaces, producing correct full name.
🧠 Conceptual
expert2:00remaining
Difference between CONCAT and CONCAT_WS behavior
Which statement correctly describes the difference between CONCAT and CONCAT_WS functions in SQL?
Attempts:
2 left
💡 Hint
Think about how each function treats NULL values and separators.
✗ Incorrect
CONCAT returns NULL if any argument is NULL. CONCAT_WS skips NULL arguments and does not add separators for them.